public ActionResult SaveRequest(RequestModel model) { if (!User.Identity.IsAuthenticated) return View("NotLogged"); model.Request.Location = HttpUtility.HtmlDecode(model.Request.Location); using (var session = new RBEPortalServer.RBEPortalContext()) { var userId = session.RBEPortalData.Users.Where(o => o.LoweredUserName == User.Identity.Name.ToLower()).Select(o => o.UserId).Single(); Request request; if (model.Request.RequestId == Guid.Empty) request = null; else request = session.RBEPortalData.Requests.SingleOrDefault(o => o.RequestId == model.Request.RequestId); if (request == null) { request = new Request { RequestId = Guid.NewGuid(), ResourceId = model.Request.ResourceId, UserId = userId, Status = "active", CreationDate = DateTime.Now, }; session.RBEPortalData.Requests.Add(request); } request.Amount = model.Request.Amount; request.UoM = model.Request.UoM; request.Location = model.Request.Location; request.ModifiedDate = DateTime.Now; request.ModifiedBy = userId; session.RBEPortalData.SaveChanges(); } return DisplayResource(model.Request.ResourceId); }
public ActionResult NewRequest(Guid resourceId) { var model = new RequestModel(); using (var session = new RBEPortalServer.RBEPortalContext()) { var resource = session.RBEPortalData.Resources.Single(o => o.ResourceId == resourceId); model.Request = new Request { ResourceId = resourceId, Resource = resource, }; } return View("CreateRequest", model); }