public string CreateSkill(ReqSkillVM req) { if (req is null) { ExceptionBase.ThrowException(404, "Skill Req is empty , make sure of providing Requird Data!", "Skill Req is empty , make sure of providing Requird Data!"); } var IsSkillAdded = unitOfWork.GetRepository <Tbl_Skills>().GetSingle(e => e.SkillName.Equals(req.SkillName)); if (!(IsSkillAdded is null)) { return(IsSkillAdded.Code.ToString()); } var NewSkill = new Tbl_Skills() { SkillName = req.SkillName, Rate = req.Rate }; if (NewSkill is null) { ExceptionBase.ThrowException(500, "Cannot Parse req object to Tbl_Skills", "Cannot Parse req object to Tbl_Skills"); } unitOfWork.GetRepository <Tbl_Skills>().Add(NewSkill); unitOfWork.SaveChanges(); return(NewSkill.Code.ToString()); }
public IActionResult Put(string SkillId, [FromBody] ReqSkillVM req) { var result = service.UpdateSkillRecord(req, SkillId); return(Ok(new SuccessResponse <string> { Code = 200, Data = result })); }
public IActionResult Post([FromBody] ReqSkillVM req) { var result = service.CreateSkill(req); return(Ok(new SuccessResponse <string> { Code = 200, Data = result })); }
public string UpdateSkillRecord(ReqSkillVM req, string SkillId) { if (req is null) { ExceptionBase.ThrowException(404, "Skill Req is empty , make sure of providing Requird Data!", "Skill Req is empty , make sure of providing Requird Data!"); } if (SkillId == default || string.IsNullOrWhiteSpace(SkillId)) { ExceptionBase.ThrowException(404, "Skill ID is null or Empty. ", "Skill ID is null or Empty. "); } var IsFoundedSkill = unitOfWork.GetRepository <Tbl_Skills>().GetSingle(e => e.Code.ToString().Equals(SkillId)); if (IsFoundedSkill is null) { ExceptionBase.ThrowException(404, "that is not a Skill ID .", "that Skill is not found. "); } var UpdatedSkill = mapper.Map <Tbl_Skills>(req); IsFoundedSkill.SkillName = UpdatedSkill.SkillName; IsFoundedSkill.Rate = UpdatedSkill.Rate; unitOfWork.GetRepository <Tbl_Skills>().Update(IsFoundedSkill); unitOfWork.SaveChanges(); return("Success"); }