Exemplo n.º 1
0
        public async Task <IHttpActionResult> GetOperationalStaff(int id)
        {
            OperationalStaffDTO dto = await OperationalStaffService.SearchSingleOperationalStaffByIdAsync(id);

            if (dto != null)
            {
                return(Ok(dto));
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> UpdateOperationalStaff([FromBody] OperationalStaffDTO OperationalStaffModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var updatedOperationalStaff = await OperationalStaffService.UpdateOperationalStaffAsync(OperationalStaffModel);

            if (updatedOperationalStaff != null)
            {
                return(Ok(updatedOperationalStaff));
            }
            else
            {
                return(NotFound());
            }
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> RegisterOperationalStaff(OperationalStaffRegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.Email, Email = model.Email
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            var newUser = UserManager.FindByEmail(model.Email);

            UserManager.AddToRoles(newUser.Id, new string[] { "Admin" });

            int stfId = 0;

            if (result.Succeeded)
            {
                OperationalStaffDTO stf = new OperationalStaffDTO()
                {
                    OpStaffName      = model.FirstName + " " + model.LastName,
                    OpStaffRole      = model.OpStaffRole,
                    StartDate        = model.StartDate,
                    OpStaffAddress1  = model.OpStaffAddress1,
                    OpStaffAddress2  = model.OpStaffAddress2,
                    OpStaffPostCode  = model.OpStaffPostCode,
                    OpStaffEmail     = model.Email,
                    OpStaffTelephone = model.OpStaffTelephone,
                    UserId           = user.Id,
                    _ImageFileUrl    = model._ImageFileUrl,
                    SchoolId         = model.SchoolId
                };
                IOperationalStaffService stfService = new OperationalStaffService();
                stfId = await stfService.AddOperationalStaffAsync(stf);
            }
            else
            {
                return(GetErrorResult(result));
            }

            return(Ok(stfId));
        }
Exemplo n.º 4
0
        public async Task <IHttpActionResult> AddOperationalStaff([FromBody] OperationalStaffDTO OperationalStaffModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var newOperationalStaffId = await OperationalStaffService.AddOperationalStaffAsync(OperationalStaffModel);

            if (newOperationalStaffId != 0)
            {
                return(Ok(newOperationalStaffId));
            }
            else
            {
                return(NotFound());
            }
        }
        //Update OperationalStaff (async)
        public async Task <OperationalStaffDTO> UpdateOperationalStaffAsync(OperationalStaffDTO modelDTO)
        {
            try
            {
                using (var unitOfWork = unitOfWorkFactory.Create())
                {
                    if (!string.IsNullOrEmpty(modelDTO._ImageFileUrl))
                    {
                        var tempImageTypeModel = unitOfWork.ImageFileTypeRepository.GetSingleOrDefaultImageFileType(x => x.Type.Contains("OperationalStaffImage"));

                        ImageFileTypeDTO imageFileTypeDTO = _Mapper_ToDTO.Map <ImageFileTypeModel, ImageFileTypeDTO>(tempImageTypeModel);

                        modelDTO.ImageFileUrl = new ImageFileUrlDTO()
                        {
                            Url             = modelDTO._ImageFileUrl,
                            CreateDate      = DateTime.Now,
                            ImageFileTypeId = imageFileTypeDTO.ImageFileTypeId
                        };
                    }
                    else
                    {
                        modelDTO.ImageFileUrl = null;
                    }

                    OperationalStaffModel model = _Mapper_ToModel.Map <OperationalStaffDTO, OperationalStaffModel>(modelDTO);

                    bool result = unitOfWork.OperationalStaffRepository.Update(model);

                    OperationalStaffDTO modelRTN = null;
                    if (result)
                    {
                        await unitOfWork.SaveChangesAsync();

                        modelRTN = _Mapper_ToDTO.Map <OperationalStaffModel, OperationalStaffDTO>(model);
                    }
                    return(modelRTN);
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }