public ActionResult RentVideo(RentVideoModel model) { var result = new StatusModel(); var rentBL = new RentBL(); result = rentBL.RentVideo(model); return Json(result); }
public ActionResult ReturnVideo(RentVideoModel model) { var result = new StatusModel(); var rentBL = new RentBL(); result = rentBL.ReturnVideo(model); return Json(result, JsonRequestBehavior.AllowGet); }
/// <summary> /// method that executing the renting action /// </summary> /// <param name="model">model containrs user id and video id</param> /// <returns>success/nor</returns> public StatusModel RentVideo(RentVideoModel model) { var result = new StatusModel(); result.Success = true; try { using (var repository = new Repository()) { //check if user already renting video and if video is 'free' var user = repository.UserRepository.GetByKey(model.UserID); var video = repository.VideoRepository.GetByKey(model.VideoID); if (user == null || video == null) { result.Success = false; result.Message = "Bad parameters"; return result; } if (user.IsRenting || video.RenterID != null) { result.Success = false; result.Message = "rent proccess cannot be exceuted"; return result; } //commit renting user.IsRenting = true; video.RenterID = user.ID; repository.UserRepository.Commit(); } } catch (Exception ex) { result.Success = false; result.Message = "unexpected ERROR"; } return result; }