public void Add(OperationalStaffModel entity)
 {
     try
     {
         _dbContext.Entry(entity).State = EntityState.Added;
     }
     catch (Exception ex)
     {
         LogException(ex);
         throw ex;
     }
 }
        public void Remove(OperationalStaffModel entity)
        {
            try
            {
                _dbContext.Entry(entity).State = EntityState.Deleted;

                //return await (_dbContext.SaveChangesAsync());
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
        //Find Single OperationalStaff base on "term" (async)
        public async Task <OperationalStaffDTO> SearchSingleOperationalStaffByIdAsync(int Id)
        {
            try
            {
                using (var unitOfWork = unitOfWorkFactory.Create())
                {
                    OperationalStaffModel model = await Task.Run(() => unitOfWork.OperationalStaffRepository.GetSingleOrDefaultOperationalStaff(x => x.OpStaffId == Id));

                    return(_Mapper_ToDTO.Map <OperationalStaffModel, OperationalStaffDTO>(model));
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }
        //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;
            }
        }
        public bool Update(OperationalStaffModel entity)
        {
            try
            {
                //entity.School = _dbContext.Set<SchoolModel>().AsQueryable().FirstOrDefault(x => x.SchoolId == entity.SchoolId);
                var currentEntity = _dbContext.Set <OperationalStaffModel>().AsQueryable().FirstOrDefault(x => x.OpStaffId == entity.OpStaffId);
                if (currentEntity == null)
                {
                    return(false);
                }

                currentEntity.OpStaffName     = entity.OpStaffName;
                currentEntity.OpStaffAddress1 = entity.OpStaffAddress1;
                currentEntity.OpStaffAddress2 = entity.OpStaffAddress2;
                currentEntity.StartDate       = entity.StartDate;
                currentEntity.OpStaffRole     = entity.OpStaffRole;
                //currentEntity.OpStaffEmail = entity.OpStaffEmail;
                currentEntity.OpStaffPostCode  = entity.OpStaffPostCode;
                currentEntity.OpStaffTelephone = entity.OpStaffTelephone;
                //currentEntity.School = entity.School;
                currentEntity.SchoolId = entity.SchoolId;



                if (entity.ImageFileUrl != null)
                {
                    currentEntity.ImageFileUrl.Url = entity.ImageFileUrl.Url;
                }

                return(true);
            }
            catch (Exception ex)
            {
                LogException(ex);
                throw ex;
            }
        }