public ActionResult <ResultVM <bool> > Create(TechnologyVM technologyVM) { ResultVM <bool> resultVM = new ResultVM <bool>(); try { TechnologyModel technologyModel = new TechnologyModel(); mapper.Map(technologyVM, technologyModel); var result = technologyBusiness.CreateTechnology(technologyModel); mapper.Map(result, resultVM); return(resultVM); } catch (Exception ex) { resultVM.Message = ex.Message; resultVM.StatusCode = Convert.ToInt32(Enums.StatusCode.BadRequest); return(StatusCode(StatusCodes.Status400BadRequest, new { Result = resultVM })); } }
public int UpdateTech(TechnologyVM model) { using (ITExpertsContext db = new ITExpertsContext()) { Technology row = db.Technologies.Find(model.TechId); if (row != null) { row.TechDescription = model.TechDescription; row.TechName = model.TechName; db.SaveChanges(); return(1); } else { return(0); } } }
public ActionResult <ResultVM <bool> > Update(TechnologyVM technologyVM) { ResultVM <bool> resultVM = new ResultVM <bool>(); try { TechnologyModel technologyModel = new TechnologyModel(); mapper.Map(technologyVM, technologyModel); var result = technologyBusiness.UpdateTechnology(technologyModel); mapper.Map(result, resultVM); } catch (Exception ex) { Common.LogMessage(ex.Message); resultVM.Message = ex.Message; resultVM.StatusCode = Convert.ToInt32(Enums.StatusCode.BadRequest); return(StatusCode(StatusCodes.Status400BadRequest, new { Result = resultVM, Codes = new string[] { "ServerError" } })); } return(resultVM); }
public int AddTech(TechnologyVM model) { using (ITExpertsContext db = new ITExpertsContext()) { try { Technology row = new Technology() { TechName = model.TechName, TechDescription = model.TechDescription, PathId = model.PathId }; db.Technologies.Add(row); db.SaveChanges(); return(1); } catch (Exception) { return(0); } } }
public JsonResult ReturnTech(int techId) { if (techId != 0) { using (ITExpertsContext db = new ITExpertsContext()) { Technology row = db.Technologies.Find(techId); TechnologyVM model = new TechnologyVM() { TechId = row.TechId, TechName = row.TechName, TechDescription = row.TechDescription, PathId = row.PathId }; return(Json(model, JsonRequestBehavior.AllowGet)); } } else { return(null); } }