public HttpResponseMessage UpdateChore(string AuthToken, int Id, string ChoreValues) { try { _User User = new _User(UserRepository.RefreshAuthToken(AuthToken)); //get chore from Id Chore ChoreObject = JsonConvert.DeserializeObject <Chore>(ChoreValues); //get ChoreList from Choreobject var ChoreList = new _ChoreList(ChoreRepository.GetChoreList((int)ChoreObject.ChoreListId)); if (User.Id != ChoreList.UserId) { throw new Exception("Unauthorized"); } ChoreObject.IsActive = true; return(OKResponse(new _Chore(ChoreRepository.UpdateChore(Id, ChoreObject)))); } catch (Exception ex) { return(ErrorResponse(ex)); } }
public ActionResult EditChoreList(int Id = 0) { if (Session["User"] == null) { return(RedirectToAction("Index", "Register")); } var User = (_User)Session["User"]; User = new _User(UserRepository.RefreshAuthToken(User.AuthToken)); Session["User"] = User; ViewBag.User = User; if (!ChoreRepository.CanEditChoreList(User.Id, Id)) { throw new Exception("Unauthorized to edit chorelist"); } _ChoreList ChoreList = new _ChoreList(ChoreRepository.GetChoreList(Id)); if (ChoreList.StatusId == 2) { List <string> Reasons = ChoreRepository.GetInActiveReasons(Id); ViewBag.InActiveReasons = Reasons; } ViewBag.User = User; ViewBag.ChoreList = ChoreList; return(View()); }
public HttpResponseMessage GetChore(string AuthToken, int Id) { try { _User User = new _User(UserRepository.RefreshAuthToken(AuthToken)); //get chore from Id var ChoreObject = new _Chore(ChoreRepository.GetChore(Id)); //get ChoreList from Choreobject var ChoreList = new _ChoreList(ChoreRepository.GetChoreList(ChoreObject.ChoreListId)); if (User.Id != ChoreList.UserId) { throw new Exception("Unauthorized"); } return(OKResponse(ChoreObject)); } catch (Exception ex) { return(ErrorResponse(ex)); } }