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); }
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); }
public ActionResult NewEstimate() { estimate newEstimate = new estimate(); estimatevalidation estValid = new estimatevalidation(); var login = _DAOFactory.AccountDAO.getByEmail(User.Identity.Name); if (login != null) { // create new estimate newEstimate.user = login.email; newEstimate.company = login.company; newEstimate.date = DateTime.Now; newEstimate.image = "~/Content/DRELogo.png"; newEstimate.paintcost = 100.00; newEstimate.framecost = 100.00; newEstimate.bodycost = 100.00; newEstimate.isopen = true; _DAOFactory.EstimateDAO.create(newEstimate); estValid.estid = newEstimate.estid; estValid.user = login.email; estValid.permission = Permissions.Owner.ToString(); estValid.notified = true; _DAOFactory.EstimateValidationDAO.create(estValid); } return RedirectToAction("Owner", new { id = newEstimate.estid }); }