Example #1
0
        public ActionResult SaveShare(ShareModel model)
        {
            if (!User.Identity.IsAuthenticated)
                return View("NotLogged");

            model.Share.Location = HttpUtility.HtmlDecode(model.Share.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();

                Share share;
                if (model.Share.ShareId == Guid.Empty)
                    share = null;
                else
                    share = session.RBEPortalData.Shares.SingleOrDefault(o => o.ShareId == model.Share.ShareId);

                if (share == null) {
                    share = new Share {
                        ShareId = Guid.NewGuid(),
                        ResourceId = model.Share.ResourceId,
                        UserId = userId,
                        Status = "active",
                        CreationDate = DateTime.Now,
                    };
                    session.RBEPortalData.Shares.Add(share);
                }

                share.Amount = model.Share.Amount;
                share.UoM = model.Share.UoM;
                share.Location = model.Share.Location;
                share.ModifiedDate = DateTime.Now;
                share.ModifiedBy = userId;

                session.RBEPortalData.SaveChanges();
            }

            return DisplayResource(model.Share.ResourceId);
        }
Example #2
0
        public ActionResult NewShare(Guid resourceId)
        {
            var model = new ShareModel();

            using (var session = new RBEPortalServer.RBEPortalContext()) {
                var resource = session.RBEPortalData.Resources.Single(o => o.ResourceId == resourceId);

                model.Share = new Share {
                    ResourceId = resourceId,
                    Resource = resource,
                };
            }

            return View("CreateShare", model);
        }