public IHttpActionResult Put([FromBody] VMCheckList value) { if (value != null) { CheckList c = VMCheckList.GetCheckList(value, new Guid(UserId)); var g = c.Id; try { using (UnitOfWork m = new UnitOfWork(new MMAContext(), new Guid(UserId), UserEmail)) { //CheckList savedCheckList = m.CheckLists.Get(g); m.CheckLists.Update(g, c); CheckList cc = m.CheckLists.Get(g); VMCheckList v = VMCheckList.GetVmCheckList(cc); return(Ok(v)); } } catch (Exception e) { return(BadRequest(e.GetAllMessages())); } } else { return(BadRequest()); } }
public IHttpActionResult Post([FromBody] VMCheckList value) { //UserId = "2303eff9-b95e-4d3c-8397-bf4eaae25c4f"; bool icheck; try { CheckList c = VMCheckList.GetCheckList(value, new Guid(UserId)); using (UnitOfWork m = new UnitOfWork(new MMAContext(), new Guid(UserId), UserEmail)) { icheck = m.CheckLists.Insert(c); } if (icheck) { return(Created($"/api/CheckList/{c.Id}", VMCheckList.GetVmCheckList(c))); } else { return(BadRequest()); } } catch (Exception e) { return(BadRequest(e.GetAllMessages())); //throw; } }
// GET api/CheckList/5 public IHttpActionResult Get(string id) { try { Guid g = new Guid(id); //UserId = "2303eff9-b95e-4d3c-8397-bf4eaae25c4f"; using (UnitOfWork m = new UnitOfWork(new MMAContext(), new Guid(UserId), UserEmail)) { VMCheckList vm = VMCheckList.GetVmCheckList(m.CheckLists.Get(g)); if (vm == null) { return(NotFound()); } return(Ok(vm)); } } catch (Exception ex) { //todo Log Exception return(BadRequest(ex.GetAllMessages())); } }
public IHttpActionResult GetByEmployer([FromUri] string strEmployerId, [FromUri] string strStartDate, [FromUri] string strEndDate) { try { Guid employerId = new Guid(strEmployerId); DateTime startD = CommonUtils.DateTimeStringToDatetime(strStartDate); DateTime endD = CommonUtils.DateTimeStringToDatetime(strEndDate); using (UnitOfWork m = new UnitOfWork(new MMAContext(), new Guid(UserId), UserEmail)) { var l = m.CheckLists.GetByEmployer(employerId, startD, endD); List <VMCheckList> al = new List <VMCheckList>(l.Count()); foreach (var r in l) { al.Add(VMCheckList.GetVmCheckList(r)); } return(Ok(al)); } } catch (Exception e) { //ToDo Log exception return(BadRequest(e.GetAllMessages())); } }