public async Task <SingleResponse <EmployeeProffesionType> > UpdateProffesionTypeAsync(EmployeeProffesionType proffesionType, Type type) { var response = new SingleResponse <EmployeeProffesionType>(); var entity = DbContext.EmployeeProffesionType.FirstOrDefault(item => item.EmployeeId == proffesionType.EmployeeId && item.ProffesionTypeId == proffesionType.ProffesionTypeId); if (entity != null) { entity.ProffesionTypeId = proffesionType.ProffesionTypeId; DbContext.Update(entity, UserInfo); await DbContext.SaveChangesAsync(); } response.SetMessageSucssesPost(nameof(CreatePhoneMailAsync), proffesionType.EmployeeAuthorizationId); response.Model = proffesionType; return(response); }
public async Task <IActionResult> PutEmployeeAsync(int Id, [FromBody] EmployeeRequest request) { // Get Employee by Id var entity = await EmployeeService.GetEmployeesAsync(request.EmployeeId ?? 0); //// ValIdate if entity exists if (entity == null) { return(NotFound()); } var employee = request.ToEntity(); // employee.UserInsert = UserInfo.UserId; employee.EmployeeId = Id; var employeeResponse = await EmployeeService.UpdateEmployeeAsync(employee); employeeResponse.Message = string.Format("Sucsses Put for Site Employee = {0} ", request.EmployeeId); if (request.PhoneNumber != null) { //update phone PhoneMail phoneMail = new PhoneMail(); phoneMail.PhoneNumber = request.PhoneNumber; phoneMail.Email = request.Email; phoneMail.EntityTypeId = (int)EntityTypeEnum.Employee; phoneMail.EntityId = employeeResponse.Model.EmployeeId; var res = await EmployeeService.UpdatePhoneMailAsync(phoneMail, typeof(Employee)); if (res.DIdError) { employeeResponse.SetMessageErrorUpdate(nameof(PhoneMail), res.Message); } } if (request.ProffesionTypeId != null) { EmployeeProffesionType proffesionType = new EmployeeProffesionType(); proffesionType.ProffesionTypeId = request.ProffesionTypeId; proffesionType.EmployeeId = employeeResponse.Model.EmployeeId; var res = await EmployeeService.UpdateProffesionTypeAsync(proffesionType, typeof(Employee)); if (res.DIdError) { employeeResponse.SetMessageErrorUpdate(nameof(ProffesionType), res.Message); } } //upload picture to blob Docs docs = new Docs(); docs.EntityTypeId = (int)EntityTypeEnum.Employee; docs.EntityId = Id; var fileName = employee.IdentityNumber + employee.FirstNameEn + "_" + employee.LastNameEn; var DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.picture, (int)DocumentType.FaceImage); employeeResponse.Model.picturePath = DOCSResponse.Model.DocumentPath; if (DOCSResponse.DIdError) { employeeResponse.SetMessageErrorUpdate("FaceImage", DOCSResponse.Message); } DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.IdentityFile, (int)DocumentType.CopyofID); employeeResponse.Model.IdentityFilePath = DOCSResponse.Model.DocumentPath; if (DOCSResponse.DIdError) { employeeResponse.SetMessageErrorUpdate("CopyofID", DOCSResponse.Message); } DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.PassportFile, (int)DocumentType.CopyPassport); employeeResponse.Model.PassportFilePath = DOCSResponse.Model.DocumentPath; if (DOCSResponse.DIdError) { employeeResponse.SetMessageErrorUpdate("CopyPassport", DOCSResponse.Message); } return(employeeResponse.ToHttpResponse()); }
public async Task <SingleResponse <EmployeeProffesionType> > CreateEmployeeProffesionTypeAsync(EmployeeProffesionType proffesionType, Type type) { var response = new SingleResponse <EmployeeProffesionType>(); DbContext.Add(proffesionType, UserInfo); await DbContext.SaveChangesAsync(); response.SetMessageSucssesPost(nameof(CreateEmployeeProffesionTypeAsync), proffesionType.EmployeeAuthorizationId); response.Model = proffesionType; return(response); }
public async Task <IActionResult> PostEmployeeAsync([FromBody] EmployeeRequest request) { if (!request.AgreeOnTheBylaws) { ModelState.AddModelError("AgreeOnTheBylaws", "Employee not Agree On The Bylaws"); } var existingEntity = await EmployeeService.GetEmployeeByIdentityNumberAsync(request.IdentityNumber); if (existingEntity.Model != null) { ModelState.AddModelError("EmployeeIdentityNumber", "תעודת הזהות קיימת במערכת"); } if (!ModelState.IsValid) { throw new Exception(); } var entity = request.ToEntity(); entity.UserInsert = UserInfo.UserId; var employeeResponse = await EmployeeService.CreateEmployeeAsync(entity); if (request.PhoneNumber != null) { PhoneMail phoneMail = new PhoneMail(); phoneMail.PhoneNumber = request.PhoneNumber; phoneMail.Email = request.Email; phoneMail.EntityTypeId = (int)EntityTypeEnum.Employee; phoneMail.EntityId = employeeResponse.Model.EmployeeId; var res = await EmployeeService.CreatePhoneMailAsync(phoneMail, typeof(Employee)); if (res.DIdError) { employeeResponse.SetMessageErrorCreate(nameof(PhoneMail), res.Message); } } if (request.ProffesionTypeId != null) { EmployeeProffesionType proffesionType = new EmployeeProffesionType(); proffesionType.ProffesionTypeId = request.ProffesionTypeId; proffesionType.EmployeeId = employeeResponse.Model.EmployeeId; var res = await EmployeeService.CreateEmployeeProffesionTypeAsync(proffesionType, typeof(Employee)); if (res.DIdError) { employeeResponse.SetMessageErrorCreate(nameof(ProffesionType), res.Message); } } Docs docs = new Docs(); docs.EntityTypeId = (int)EntityTypeEnum.Employee; docs.EntityId = employeeResponse.Model.EmployeeId; var fileName = employeeResponse.Model.IdentityNumber + "FaceImage"; //יש לבדוק אם אכן זה עובד //upload picture to blob var DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.picture, (int)DocumentType.FaceImage); employeeResponse.Model.picturePath = DOCSResponse.Model.DocumentPath; if (DOCSResponse.DIdError) { employeeResponse.SetMessageErrorUpdate("FaceImage", DOCSResponse.Message); } docs = new Docs(); docs.EntityTypeId = (int)EntityTypeEnum.Employee; docs.EntityId = employeeResponse.Model.EmployeeId; fileName = employeeResponse.Model.IdentityNumber + "CopyofID"; DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.IdentityFile, (int)DocumentType.CopyofID); employeeResponse.Model.IdentityFilePath = DOCSResponse.Model.DocumentPath; if (DOCSResponse.DIdError) { employeeResponse.SetMessageErrorUpdate("CopyofID", DOCSResponse.Message); } docs = new Docs(); docs.EntityTypeId = (int)EntityTypeEnum.Employee; docs.EntityId = employeeResponse.Model.EmployeeId; fileName = employeeResponse.Model.IdentityNumber + "CopyPassport"; DOCSResponse = await EmployeeService.CreateDocsAsync(docs, typeof(Employee), fileName, request.PassportFile, (int)DocumentType.CopyPassport); employeeResponse.Model.PassportFilePath = DOCSResponse.Model.DocumentPath; if (DOCSResponse.DIdError) { employeeResponse.SetMessageErrorUpdate("CopyPassport", DOCSResponse.Message); } SiteEmployee siteEmployee = new SiteEmployee(); siteEmployee.EmployeeId = employeeResponse.Model.EmployeeId; siteEmployee.SiteId = request.SiteId; var response = await EmployeeService.CreateSiteEmployeeAsync(siteEmployee); return(employeeResponse.ToHttpResponse()); }