public async Task <AppDomainResult> UpdateExaminationStatus([FromBody] UpdateExaminationStatusModel updateExaminationStatusModel) { AppDomainResult appDomainResult = new AppDomainResult(); if (ModelState.IsValid) { var updateExaminationStatus = mapper.Map <UpdateExaminationStatus>(updateExaminationStatusModel); bool isSuccess = await this.examinationFormService.UpdateExaminationStatus(updateExaminationStatus); if (isSuccess) { appDomainResult.Success = isSuccess; appDomainResult.ResultCode = (int)HttpStatusCode.OK; } else { throw new Exception("Lỗi trong quá trình xử lý"); } } else { throw new AppException(ModelState.GetErrorMessage()); } return(appDomainResult); }
public virtual async Task <AppDomainResult> UploadFiles(List <IFormFile> files) { AppDomainResult appDomainResult = new AppDomainResult(); await Task.Run(() => { if (files != null && files.Any()) { List <string> fileNames = new List <string>(); foreach (var file in files) { string fileName = string.Format("{0}-{1}", Guid.NewGuid().ToString(), file.FileName); string fileUploadPath = Path.Combine(env.ContentRootPath, "temp"); string path = Path.Combine(fileUploadPath, fileName); FileUtils.CreateDirectory(fileUploadPath); var fileByte = FileUtils.StreamToByte(file.OpenReadStream()); FileUtils.SaveToPath(path, fileByte); fileNames.Add(fileName); } appDomainResult = new AppDomainResult() { Success = true, Data = fileNames }; } }); return(appDomainResult); }
public virtual async Task <AppDomainResult> ChangePassword(int userId, [FromBody] ChangePasswordModel changePasswordModel) { AppDomainResult appDomainResult = new AppDomainResult(); if (ModelState.IsValid) { // Check current user if (LoginContext.Instance.CurrentUser.UserId != userId) { throw new AppException("Không phải người dùng hiện tại"); } // Check old Password + new Password string messageCheckPassword = await this.userService.CheckCurrentUserPassword(userId, changePasswordModel.OldPassword, changePasswordModel.NewPassword); if (!string.IsNullOrEmpty(messageCheckPassword)) { throw new AppException(messageCheckPassword); } var userInfo = await this.userService.GetByIdAsync(userId); userInfo.Password = SecurityUtils.HashSHA1(changePasswordModel.NewPassword); appDomainResult.Success = await userService.UpdateAsync(userInfo); appDomainResult.ResultCode = (int)HttpStatusCode.OK; } else { throw new AppException(ModelState.GetErrorMessage()); } return(appDomainResult); }
public override async Task <AppDomainResult> UpdateItem(int id, [FromBody] UserModel itemModel) { if (LoginContext.Instance.CurrentUser.UserId != id) { throw new UnauthorizedAccessException("Không có quyền truy cập"); } AppDomainResult appDomainResult = new AppDomainResult(); bool success = false; if (ModelState.IsValid) { var item = mapper.Map <Users>(itemModel); if (item != null) { // Kiểm tra item có tồn tại chưa? var messageUserCheck = await this.domainService.GetExistItemMessage(item); if (!string.IsNullOrEmpty(messageUserCheck)) { throw new AppException(messageUserCheck); } item.Updated = DateTime.Now; item.UpdatedBy = LoginContext.Instance.CurrentUser.UserName; Expression <Func <Users, object> >[] includeProperties = new Expression <Func <Users, object> >[] { x => x.FirstName, x => x.LastName, x => x.Email, x => x.Phone, x => x.Updated, x => x.UpdatedBy, x => x.UserName, x => x.Age, x => x.Address, }; success = await this.domainService.UpdateFieldAsync(item, includeProperties); if (success) { appDomainResult.ResultCode = (int)HttpStatusCode.OK; } else { throw new Exception("Lỗi trong quá trình xử lý"); } appDomainResult.Success = success; } else { throw new KeyNotFoundException("Item không tồn tại"); } } else { throw new AppException(ModelState.GetErrorMessage()); } return(appDomainResult); }
public async Task <AppDomainResult> UpdateEmailConfiguration([FromBody] EmailConfigurationModel emailConfigurationModel) { AppDomainResult appDomainResult = new AppDomainResult(); if (ModelState.IsValid) { emailConfigurationModel.EncryptPassword(); var emailConfiguration = mapper.Map <EmailConfiguration>(emailConfigurationModel); bool success = await this.emailConfigurationService.UpdateAsync(emailConfiguration); if (success) { appDomainResult = new AppDomainResult() { Success = true, ResultCode = (int)HttpStatusCode.OK, }; } else { throw new Exception("Lỗi trong quá trình xử lý!"); } } else { throw new AppException(ModelState.GetErrorMessage()); } return(appDomainResult); }
public override async Task <AppDomainResult> PatchItem(int id, [FromBody] T itemModel) { AppDomainResult appDomainResult = new AppDomainResult(); bool success = false; itemModel.Updated = DateTime.Now; itemModel.UpdatedBy = LoginContext.Instance.CurrentUser.UserName; var item = mapper.Map <E>(itemModel); if (item != null) { Expression <Func <E, object> >[] includeProperties = new Expression <Func <E, object> >[] { x => x.Active, }; success = await this.catalogueService.UpdateFieldAsync(item, includeProperties); if (success) { appDomainResult.ResultCode = (int)HttpStatusCode.OK; } else { throw new Exception("Lỗi trong quá trình xử lý"); } appDomainResult.Success = success; } else { throw new KeyNotFoundException("Item không tồn tại"); } return(appDomainResult); }
public override async Task <AppDomainResult> GetById(int id) { AppDomainResult appDomainResult = new AppDomainResult(); try { var item = await this.catalogueService.GetByIdAsync(id); if (item != null) { var itemModel = mapper.Map <PermitObjectModel>(item); itemModel.ToView(); appDomainResult = new AppDomainResult() { Success = true, Data = itemModel, ResultCode = (int)HttpStatusCode.OK }; } else { throw new KeyNotFoundException("Item không tồn tại"); } } catch (Exception ex) { this.logger.LogError(string.Format("{0} {1}: {2}", this.ControllerContext.RouteData.Values["controller"].ToString(), "GetById", ex.Message)); throw new Exception(ex.Message); } return(appDomainResult); }
public async Task <AppDomainResult> GetCatalogueController() { return(await Task.Run(() => { AppDomainResult appDomainResult = new AppDomainResult(); AppDomain currentDomain = AppDomain.CurrentDomain; Assembly[] assems = currentDomain.GetAssemblies(); var controllers = new List <ControllerModel>(); foreach (Assembly assem in assems) { var controller = assem.GetTypes().Where(type => typeof(Controller).IsAssignableFrom(type) && !type.IsAbstract) .Select(e => new ControllerModel() { Id = e.Name.Replace("Controller", string.Empty), Name = string.Format("{0}", ReflectionUtils.GetClassDescription(e)).Replace("Controller", string.Empty) }).OrderBy(e => e.Name) .Distinct(); controllers.AddRange(controller); } appDomainResult = new AppDomainResult() { Data = controllers, Success = true, ResultCode = (int)HttpStatusCode.OK }; return appDomainResult; })); }
public virtual async Task <AppDomainResult> GetById(int id) { AppDomainResult appDomainResult = new AppDomainResult(); if (id == 0) { throw new KeyNotFoundException("id không tồn tại"); } var item = await this.domainService.GetByIdAsync(id); if (item != null) { var itemModel = mapper.Map <T>(item); appDomainResult = new AppDomainResult() { Success = true, Data = itemModel, ResultCode = (int)HttpStatusCode.OK }; } else { throw new KeyNotFoundException("Item không tồn tại"); } return(appDomainResult); }
public override async Task <AppDomainResult> PatchItem(int id, [FromBody] UserModel itemModel) { AppDomainResult appDomainResult = new AppDomainResult(); bool success = false; var item = mapper.Map <Users>(itemModel); if (item != null) { Expression <Func <Users, object> >[] includeProperties = new Expression <Func <Users, object> >[] { x => x.Active, x => x.Status }; success = await this.domainService.UpdateFieldAsync(item, includeProperties); appDomainResult.ResultCode = (int)HttpStatusCode.OK; appDomainResult.Success = success; } else { appDomainResult.ResultCode = (int)HttpStatusCode.InternalServerError; appDomainResult.Success = false; } return(appDomainResult); }
public override async Task <AppDomainResult> Register([FromBody] RegisterModel register) { AppDomainResult appDomainResult = new AppDomainResult(); if (ModelState.IsValid) { // Kiểm tra định dạng user name bool isValidUser = ValidateUserName.IsValidUserName(register.UserName); if (!isValidUser) { throw new AppException("Vui lòng nhập số điện thoại hoặc email!"); } var user = new Users() { UserName = register.UserName, Password = register.Password, Created = DateTime.Now, CreatedBy = register.UserName, Active = true, Phone = ValidateUserName.IsPhoneNumber(register.UserName) ? register.UserName : string.Empty, Email = ValidateUserName.IsEmail(register.UserName) ? register.UserName : string.Empty, UserInGroups = new List <UserInGroups>(), }; // Tạo mặc định trong group User var groupUserInfos = await userGroupService.GetAsync(e => e.Code == CoreContants.USER_GROUP); if (groupUserInfos != null && groupUserInfos.Any()) { UserInGroups userInGroups = new UserInGroups() { UserGroupId = groupUserInfos.FirstOrDefault().Id, Created = DateTime.Now, CreatedBy = register.UserName, Deleted = false, Active = true, }; user.UserInGroups.Add(userInGroups); } // Kiểm tra item có tồn tại chưa? var messageUserCheck = await this.userService.GetExistItemMessage(user); if (!string.IsNullOrEmpty(messageUserCheck)) { throw new AppException(messageUserCheck); } user.Password = SecurityUtils.HashSHA1(register.Password); appDomainResult.Success = await userService.CreateAsync(user); appDomainResult.ResultCode = (int)HttpStatusCode.OK; } else { var resultMessage = ModelState.GetErrorMessage(); throw new AppException(resultMessage); } return(appDomainResult); }
public async Task <AppDomainResult> GetEmailConfiguration() { AppDomainResult appDomainResult = new AppDomainResult(); // Lấy thông tin cấu hình var configurations = await this.emailConfigurationService.GetAsync(e => !e.Deleted && e.Active, e => new EmailConfiguration() { Id = e.Id, Deleted = e.Deleted, Active = e.Active, Email = e.Email, EnableSsl = e.EnableSsl, Port = e.Port, DisplayName = e.DisplayName, Created = e.Created, CreatedBy = e.CreatedBy, SmtpServer = e.SmtpServer, ConnectType = e.ConnectType, ItemSendCount = e.ItemSendCount, TimeSend = e.TimeSend, UserName = e.UserName, Password = string.Empty }); if (configurations != null && configurations.Any()) { appDomainResult = new AppDomainResult() { Success = true, ResultCode = (int)HttpStatusCode.OK, Data = mapper.Map <EmailConfigurationModel>(configurations.FirstOrDefault()) }; } // Chưa có cấu hình => tạo mới cấu hình else { EmailConfiguration emailConfiguration = new EmailConfiguration() { Deleted = false, Active = true, Created = DateTime.Now, CreatedBy = LoginContext.Instance.CurrentUser.UserName, SmtpServer = string.Empty, DisplayName = string.Empty, Password = string.Empty, UserName = string.Empty, }; bool success = await this.emailConfigurationService.CreateAsync(emailConfiguration); appDomainResult = new AppDomainResult() { Success = true, ResultCode = (int)HttpStatusCode.OK, Data = mapper.Map <EmailConfigurationModel>(emailConfiguration) }; } return(appDomainResult); }
public virtual async Task <AppDomainResult> ForgotPassword(string userName) { AppDomainResult appDomainResult = new AppDomainResult(); bool isValidEmail = ValidateUserName.IsEmail(userName); bool isValidPhone = ValidateUserName.IsPhoneNumber(userName); // Kiểm tra đúng định dạng email và số điện thoại chưa if (!isValidEmail && !isValidPhone) { throw new AppException("Vui lòng nhập email hoặc số điện thoại!"); } // Tạo mật khẩu mới // Kiểm tra email/phone đã tồn tại chưa? var userInfos = await this.userService.GetAsync(e => !e.Deleted && (e.UserName == userName || e.Email == userName || e.Phone == userName ) ); Users userInfo = null; if (userInfos != null && userInfos.Any()) { userInfo = userInfos.FirstOrDefault(); } if (userInfo == null) { throw new AppException("Số điện thoại hoặc email không tồn tại"); } // Cấp mật khẩu mới var newPasswordRandom = RandomUtilities.RandomString(8); userInfo.Password = SecurityUtils.HashSHA1(newPasswordRandom); bool success = await this.userService.UpdateAsync(userInfo); if (success) { // Gửi mã qua Email if (isValidEmail) { string emailBody = string.Format("<p>Your new password: {0}</p>", newPasswordRandom); emailConfigurationService.Send("Change Password", new string[] { userInfo.Email }, null, null, new EmailContent() { Content = emailBody, IsHtml = true, }); } // Gửi SMS else if (isValidPhone) { } } return(appDomainResult); }
public async Task <AppDomainResult> GetDoctorDetails(int doctorId) { AppDomainResult appDomainResult = new AppDomainResult(); var doctorDetails = await this.doctorDetailService.GetAsync(e => !e.Deleted && e.DoctorId == doctorId); var doctorDetailModels = mapper.Map <IList <DoctorDetailModel> >(doctorDetails); appDomainResult.Success = true; appDomainResult.ResultCode = (int)HttpStatusCode.OK; appDomainResult.Data = doctorDetailModels; return(appDomainResult); }
public async Task <AppDomainResult> GetSessionType() { AppDomainResult appDomainResult = new AppDomainResult(); var sessionTypes = await this.sessionTypeService.GetAsync(e => !e.Deleted && e.Active); appDomainResult = new AppDomainResult() { Success = true, Data = mapper.Map <IList <SessionTypeModel> >(sessionTypes) }; return(appDomainResult); }
public async Task <AppDomainResult> GetExaminationScheduleDetails(int examinationScheduleId) { AppDomainResult appDomainResult = new AppDomainResult(); var examinationSchedules = await this.examinationScheduleDetailService.GetAsync(e => !e.Deleted && e.ScheduleId == examinationScheduleId); var examinationScheduleModels = mapper.Map <IList <ExaminationScheduleDetails> >(examinationSchedules); appDomainResult.Success = true; appDomainResult.ResultCode = (int)HttpStatusCode.OK; appDomainResult.Data = examinationScheduleModels; return(appDomainResult); }
public virtual async Task <AppDomainResult> Logout() { AppDomainResult appDomainResult = new AppDomainResult(); await this.tokenManagerService.DeactivateCurrentAsync(); appDomainResult = new AppDomainResult() { Success = true, ResultCode = (int)HttpStatusCode.OK }; return(appDomainResult); }
public async Task <AppDomainResult> GetConfigTimeExamination(int sesstionTypeId) { AppDomainResult appDomainResult = new AppDomainResult(); var configTimeExaminations = await this.configTimeExaminationService.GetAsync(e => !e.Deleted && e.Active && e.SessionId == sesstionTypeId); appDomainResult = new AppDomainResult() { Success = true, Data = mapper.Map <IList <ConfigTimeExamniationModel> >(configTimeExaminations) }; return(appDomainResult); }
public async Task <AppDomainResult> GetListRelation() { AppDomainResult appDomainResult = new AppDomainResult(); var relations = await this.relationService.GetAsync(e => !e.Deleted && e.Active); var relationModels = mapper.Map <IList <RelationModel> >(relations); appDomainResult = new AppDomainResult() { Success = true, Data = relationModels }; return(appDomainResult); }
public async Task <AppDomainResult> GetDoctorByHospital(int hospitalId) { AppDomainResult appDomainResult = new AppDomainResult(); var doctorByHospitals = await this.doctorService.GetAsync(e => !e.Deleted && e.Active && e.HospitalId == hospitalId); var doctorModels = mapper.Map <IList <DoctorModel> >(doctorByHospitals); appDomainResult = new AppDomainResult() { Success = true, Data = doctorModels }; return(appDomainResult); }
public async Task <AppDomainResult> GetSpecialistTypeByHospital(int hospitalId) { AppDomainResult appDomainResult = new AppDomainResult(); var specialistTypes = await this.specialListTypeService.GetAsync(e => !e.Deleted && e.Active && e.HospitalId == hospitalId); var specialistTypeModels = mapper.Map <IList <SpecialistTypeModel> >(specialistTypes); appDomainResult = new AppDomainResult() { Success = true, Data = specialistTypeModels }; return(appDomainResult); }
public async Task <AppDomainResult> GetUserInGroups([FromQuery] SearchUserInGroup searchUserInGroup) { AppDomainResult appDomainResult = new AppDomainResult(); var pagedList = await this.userInGroupService.GetPagedListData(searchUserInGroup); var pagedListModel = mapper.Map <PagedList <UserInGroupModel> >(pagedList); appDomainResult = new AppDomainResult() { Data = pagedListModel, Success = true, ResultCode = (int)HttpStatusCode.OK }; return(appDomainResult); }
public async Task <AppDomainResult> GetMedicalAdditionInfos(int medicalRecordId) { AppDomainResult appDomainResult = new AppDomainResult(); var medicalRecordAdditionInfos = await this.medicalRecordAdditionService.GetAsync(e => !e.Deleted && e.MedicalRecordId == medicalRecordId); var medicalRecordAdditionInfoModels = mapper.Map <IList <MedicalRecordAdditionModel> >(medicalRecordAdditionInfos); appDomainResult = new AppDomainResult() { ResultCode = (int)HttpStatusCode.OK, Success = true, Data = medicalRecordAdditionInfoModels, }; return(appDomainResult); }
public async Task <AppDomainResult> GetExaminationHistory(int examinationFormId) { AppDomainResult appDomainResult = new AppDomainResult(); var examinationForms = await this.examinationHistoryService.GetAsync(x => !x.Deleted && x.ExaminationFormId == examinationFormId); var examinationFormModels = mapper.Map <IList <ExaminationHistoryModel> >(examinationForms); appDomainResult = new AppDomainResult() { Success = true, ResultCode = (int)HttpStatusCode.OK, Data = examinationFormModels }; return(appDomainResult); }
public async Task <AppDomainResult> GetListDateExaminationByHospital(int hospitalId) { AppDomainResult appDomainResult = new AppDomainResult(); var schedules = await this.examinationScheduleService.GetAsync(e => !e.Deleted && e.Active && e.HospitalId == hospitalId && e.ExaminationDate.Date >= DateTime.Now.Date ); appDomainResult = new AppDomainResult() { Success = true, Data = mapper.Map <IList <ExaminationScheduleModel> >(schedules) }; return(appDomainResult); }
public virtual async Task <AppDomainResult> Get() { AppDomainResult appDomainResult = new AppDomainResult(); var items = await this.domainService.GetAllAsync(); var itemModels = mapper.Map <IList <T> >(items); appDomainResult = new AppDomainResult() { Success = true, Data = itemModels, ResultCode = (int)HttpStatusCode.OK }; return(appDomainResult); }
public override async Task <AppDomainResult> DeleteItem(int id) { AppDomainResult appDomainResult = new AppDomainResult(); bool success = await this.catalogueService.DeleteAsync(id); if (success) { appDomainResult.ResultCode = (int)HttpStatusCode.OK; appDomainResult.Success = success; } else { throw new Exception("Lỗi trong quá trình xử lý"); } return(appDomainResult); }
public override async Task <AppDomainResult> GetById(int id) { AppDomainResult appDomainResult = new AppDomainResult(); if (LoginContext.Instance.CurrentUser.UserId != id) { throw new UnauthorizedAccessException("Không có quyền truy cập"); } if (id == 0) { throw new KeyNotFoundException("id không tồn tại"); } var item = await this.domainService.GetByIdAsync(id, e => new Users() { Id = e.Id, Deleted = e.Deleted, Active = e.Active, Created = e.Created, CreatedBy = e.CreatedBy, Address = e.Address, Age = e.Age, FirstName = e.FirstName, LastName = e.LastName, Email = e.Email, Phone = e.Phone, UserName = e.UserName, Updated = e.Updated, UpdatedBy = e.UpdatedBy, }); if (item != null) { var itemModel = mapper.Map <UserModel>(item); appDomainResult = new AppDomainResult() { Success = true, Data = itemModel, ResultCode = (int)HttpStatusCode.OK }; } else { throw new KeyNotFoundException("Item không tồn tại"); } return(appDomainResult); }
public override async Task <AppDomainResult> UpdateItem(int id, [FromBody] T itemModel) { AppDomainResult appDomainResult = new AppDomainResult(); bool success = false; if (ModelState.IsValid) { itemModel.Updated = DateTime.Now; itemModel.UpdatedBy = LoginContext.Instance.CurrentUser.UserName; var item = mapper.Map <E>(itemModel); if (item != null) { // Kiểm tra item có tồn tại chưa? var messageUserCheck = await this.catalogueService.GetExistItemMessage(item); if (!string.IsNullOrEmpty(messageUserCheck)) { throw new AppException(messageUserCheck); } success = await this.catalogueService.UpdateAsync(item); if (success) { appDomainResult.ResultCode = (int)HttpStatusCode.OK; } else { throw new Exception("Lỗi trong quá trình xử lý"); } appDomainResult.Success = success; } else { throw new KeyNotFoundException("Item không tồn tại"); } } else { throw new AppException(ModelState.GetErrorMessage()); } return(appDomainResult); }
public virtual async Task <AppDomainResult> Register([FromBody] RegisterModel register) { AppDomainResult appDomainResult = new AppDomainResult(); if (ModelState.IsValid) { // Kiểm tra định dạng user name bool isValidUser = ValidateUserName.IsValidUserName(register.UserName); if (!isValidUser) { throw new AppException("Vui lòng nhập số điện thoại hoặc email!"); } var user = new Users() { UserName = register.UserName, Password = register.Password, Created = DateTime.Now, CreatedBy = register.UserName, Active = true, Phone = ValidateUserName.IsPhoneNumber(register.UserName) ? register.UserName : string.Empty, Email = ValidateUserName.IsEmail(register.UserName) ? register.UserName : string.Empty, }; // Kiểm tra item có tồn tại chưa? var messageUserCheck = await this.userService.GetExistItemMessage(user); if (!string.IsNullOrEmpty(messageUserCheck)) { throw new AppException(messageUserCheck); } user.Password = SecurityUtils.HashSHA1(register.Password); appDomainResult.Success = await userService.CreateAsync(user); appDomainResult.ResultCode = (int)HttpStatusCode.OK; } else { var resultMessage = ModelState.GetErrorMessage(); throw new AppException(resultMessage); } return(appDomainResult); }