public string CreateEmployer(ReqEmployerVM req) { if (req is null) { ExceptionBase.ThrowException(404, "Employer Req is empty , make sure of providing Requird Data!", "Employer Req is empty , make sure of providing Requird Data!"); } var IsEmployerAdded = unitOfWork.GetRepository <Tbl_Employer>().GetSingle(e => e.EmployerName.Equals(req.EmployerName)); if (!(IsEmployerAdded is null)) { return(IsEmployerAdded.Code.ToString()); } var NewEmployer = new Tbl_Employer() { EmployerName = req.EmployerName }; if (NewEmployer is null) { ExceptionBase.ThrowException(500, "Cannot Parse req object to Tbl_Employer", "Cannot Parse req object to Tbl_Employer"); } unitOfWork.GetRepository <Tbl_Employer>().Add(NewEmployer); unitOfWork.SaveChanges(); return(NewEmployer.Code.ToString()); }
public IActionResult Put(string EmployerId, [FromBody] ReqEmployerVM req) { var result = service.UpdateEmployerProfile(req, EmployerId); return(Ok(new SuccessResponse <string> { Code = 200, Data = result })); }
public IActionResult Post([FromBody] ReqEmployerVM req) { var result = service.CreateEmployer(req); return(Ok(new SuccessResponse <string> { Code = 200, Data = result })); }
public string UpdateEmployerProfile(ReqEmployerVM req, string EmployerId) { if (req is null) { ExceptionBase.ThrowException(404, "Employer Req is empty , make sure of providing Requird Data!", "Employer Req is empty , make sure of providing Requird Data!"); } if (EmployerId == default || string.IsNullOrWhiteSpace(EmployerId)) { ExceptionBase.ThrowException(404, "Employer ID is null or Empty. ", "Employer ID is null or Empty. "); } var IsFoundedEmployer = unitOfWork.GetRepository <Tbl_Employer>().GetSingle(e => e.Code.ToString().Equals(EmployerId)); if (IsFoundedEmployer is null) { ExceptionBase.ThrowException(404, "that is not a Employer ID .", "that Employer is not found. "); } var UpdatedEmployer = mapper.Map <Tbl_Employer>(req); IsFoundedEmployer.EmployerName = UpdatedEmployer.EmployerName; unitOfWork.GetRepository <Tbl_Employer>().Update(IsFoundedEmployer); unitOfWork.SaveChanges(); return("Success"); }