Sherzy
6/9/2017 - 8:36 PM

Save method for controller - with standard created/updated

Save method for controller - with standard created/updated

public JsonResult Save(StudentModel model)
{
    var entity = Mapper.Map<Student>(model);
    if (entity.StudentId > 0)
    {
        entity.Updated = DateTime.Now;
        entity.UpdatedBy = base.HttpContext.User.Identity.Name;
        entity.ObjectState = ObjectState.Modified;
    }
    else
    {
        entity.Created = DateTime.Now;
        entity.CreatedBy = base.HttpContext.User.Identity.Name;
        entity.ObjectState = ObjectState.Added;
    }

    _studentService.SaveStudent(entity);
    var m = Mapper.Map<StudentModel>(entity);
    return Json(m, JsonRequestBehavior.AllowGet);
}