public async Task <Student> Insert(Student student) { try { Validate(student); student.CreationDate = student.ModificationDate = DateTime.Now; return(await base.Insert(student)); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw; } }
public async Task <ClassMaster> Insert(ClassMaster entity) { try { Validate(entity); entity.CreationDate = entity.ModificationDate = DateTime.Now; return(await base.Insert(entity)); } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); throw; } }
public override void OnActionExecuting(ActionExecutingContext actionContext) { try { var controller = actionContext.Controller as Controller; var identity = (ClaimsIdentity)controller.User.Identity; if (SkipAuthorization(actionContext)) { base.OnActionExecuting(actionContext); } else { var userName = identity?.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Name)?.Value; if (string.IsNullOrEmpty(userName)) { Logger.ErrorException("نام کاربری خالی است", new Exception("نام کاربری خالی است")); actionContext.Result = new HttpUnauthorizedResult(); } else { var filterType = actionContext.ActionParameters.Values.FirstOrDefault(r => r.GetType() .InheritsOrImplements(typeof(BaseDto <>))); if (filterType != null) { var filterName = actionContext.ActionParameters.FirstOrDefault(r => r.Value == filterType).Key; dynamic list = Activator.CreateInstance(filterType.GetType()); list = filterType; if (userName != null) { list.PartyId = identity.FindFirst(ClaimTypes.UserData).Value.SafeInt(); list.UserName = userName; list.UserId = identity.FindFirst(ClaimTypes.NameIdentifier).Value; //if (branch?.BranchId != null) //{ // list.BranchCode = BranchProvider.BranchService.GetKey((int)branch.BranchId).Code; // if (branch?.BranchId != null) list.BranchId = (int)branch?.BranchId; //} } actionContext.ActionParameters[filterName] = list; } } base.OnActionExecuting(actionContext); } } catch (Exception ex) { // Logger.ErrorException(exception.Message, exception); } }
public JsonResult GetStudents() { WebApiPagedCollectionResponse <StudentDto> res; try { var studentsEntity = _studentRepository.GetAll(); var lst = studentsEntity.Select(x => new StudentDto { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Age = x.Age, Gpa = x.Gpa }).ToList(); res = new WebApiPagedCollectionResponse <StudentDto> { Result = lst, TotalRecords = lst.Count, Message = ResponseMessage.OperationSucceeded.GetDescription() }; } catch (Exception ex) { Logger.ErrorException(ex.Message, ex); res = new WebApiPagedCollectionResponse <StudentDto> { ErrorFlag = true, Message = ResponseMessage.OperationFailed.GetDescription() }; } return(new JsonResult(res)); }