/// <summary> /// Method to add Occupation - SS /// </summary> /// <param name="name">name of Occupation</param> /// <param name="instituteId">institute id</param> /// <returns>message</returns> public async Task <SharedLookUpResponse> AddOccupationAsync(AddOccupationManagementAc addOccupation, int instituteId) { if (!await _iMSDbContext.Occupations.AnyAsync(x => x.InstituteId == instituteId && x.Code.ToLowerInvariant() == addOccupation.Code.ToLowerInvariant())) { var Occupation = new Occupation() { CreatedOn = DateTime.UtcNow, InstituteId = instituteId, Name = addOccupation.Name, Code = addOccupation.Code, Description = addOccupation.Description, Status = true }; _iMSDbContext.Occupations.Add(Occupation); await _iMSDbContext.SaveChangesAsync(); return(new SharedLookUpResponse() { HasError = false, Message = "Occupation added successfully" }); } else { return new SharedLookUpResponse() { HasError = true, ErrorType = SharedLookUpResponseType.Code, Message = "Occupation with the same code is already exist" } }; }
public async Task <IActionResult> AddOccupationAsync([FromBody] AddOccupationManagementAc addOccupationManagement) { if (string.IsNullOrEmpty(addOccupationManagement.Name.Trim())) { return(Ok(new SharedLookUpResponse { ErrorType = SharedLookUpResponseType.Name, HasError = true, Message = "Occupation name can't be empty" })); } else if (string.IsNullOrEmpty(addOccupationManagement.Code.Trim())) { return(Ok(new SharedLookUpResponse { ErrorType = SharedLookUpResponseType.Code, HasError = true, Message = "Occupation code can't be empty" })); } else { var loggedInUserInstituteId = await GetUserCurrentSelectedInstituteIdAsync(); return(Ok(await _occupationManagementRepository.AddOccupationAsync(addOccupationManagement, loggedInUserInstituteId))); } }