Esempio n. 1
0
 public ActionResult Share(int id, string userName, string Permission, List<ShareVM> share)
 {
     if (isValid(id) == null)
     {
         return RedirectToAction("Home", "Account");
     }
     ModelState.Clear();
     for (int i = 0; i < share.Count(); i++)
     {
         if (share[i].val.permission != "Owner")
         {
             var estVal = _DAOFactory.EstimateValidationDAO.getByestIdUser(id, share[i].val.user);
             if (estVal != null)
             {
                 if (share[i].remove)
                 {
                     _DAOFactory.EstimateValidationDAO.delete(estVal);
                     share.RemoveAt(i);
                     i--;
                 }
             }
             else
             {
                 ModelState.AddModelError("ExistedVal", "Error finding current shared entry");
             }
         }
     }
     if (userName != "")
     {
         var user = _DAOFactory.AccountDAO.getByEmail(userName);
         if (user != null)
         {
             estimatevalidation val = new estimatevalidation();
             val.estid = id;
             val.user = _DAOFactory.AccountDAO.getByEmail(userName).email;
             val.permission = Permission;
             val.notified = false;
             var currVal = _DAOFactory.EstimateValidationDAO.getByestIdUser(id, userName);
             if (currVal == null)
             {
                 _DAOFactory.EstimateValidationDAO.create(val);
                 ViewBag.Success = "You have successfully shared your estimate with " + val.user;
             }
             else if(currVal.permission != "Owner")
             {
                 _DAOFactory.EstimateValidationDAO.update(val);
                 ViewBag.Success = "You have successfully shared your estimate with " + val.user;
             }
             else if (currVal.permission == "Owner")
             {
                 ModelState.AddModelError("Error", "Cannot add this user because they are the Owner.");
             }
         }
         else
         {
             ModelState.AddModelError("Error", "Please Enter A Valid User.");
         }
     }
     share = new List<ShareVM>();
     foreach (var estVal in _DAOFactory.EstimateValidationDAO.getByEstId(id).ToList())
     {
         var val = new estimatevalidation();
         val.estid = estVal.estid;
         val.permission = estVal.permission;
         val.user = estVal.user;
         val.notified = estVal.notified;
         var shareVal = new ShareVM();
         shareVal.val = val;
         shareVal.remove = false;
         share.Add(shareVal);
     }
     return View(share);
 }
Esempio n. 2
0
 public ActionResult Share(int id)
 {
     if (isValid(id) == null)
     {
         return RedirectToAction("Home", "Account");
     }
     List<ShareVM> share = new List<ShareVM>();
     foreach (var estVal in _DAOFactory.EstimateValidationDAO.getByEstId(id).ToList())
     {
         var val = new estimatevalidation();
         val.estid = estVal.estid;
         val.permission = estVal.permission;
         val.user = estVal.user;
         val.notified = estVal.notified;
         var shareVal = new ShareVM();
         shareVal.val = val;
         shareVal.remove = false;
         share.Add(shareVal);
     }
     return View(share);
 }