예제 #1
0
        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 });
        }
예제 #2
0
        public ActionResult EstimateSettings(int id,estimate currEstimate)
        {
            currEstimate.estid = id;
            if (ModelState.IsValid)
            {
                if (isValid(id) == null)
                {
                    return RedirectToAction("Home", "Account");
                }
                if (_DAOFactory.AccountDAO.getByEmail(currEstimate.user) == null)
                {
                    ModelState.AddModelError("Error", "The user you have selected as the new owner of this estimate does not exist");
                    if (isValid(id) == "Admin")
                    {
                        ViewBag.UserPermission = "Admin";
                    }
                    else
                    {
                        ViewBag.UserPermission = _DAOFactory.EstimateValidationDAO.getByestIdUser(id, User.Identity.Name).permission;
                    }
                    return View(currEstimate);
                }
                currEstimate.user = _DAOFactory.AccountDAO.getByEmail(currEstimate.user).email;
                _DAOFactory.EstimateDAO.update(currEstimate);

                var currentVal = _DAOFactory.EstimateValidationDAO.getOwnerOfEst(id);
                _DAOFactory.EstimateValidationDAO.delete(currentVal);
                currentVal.user = _DAOFactory.AccountDAO.getByEmail(currEstimate.user).email;
                currentVal.notified = false;
                _DAOFactory.EstimateValidationDAO.create(currentVal);

                var items = _DAOFactory.EstimateItemsDAO.getByEstId(id).ToList();
                for (int i = 0; i < items.Count(); i++)
                {
                    var existingPart = _DAOFactory.PartsDAO.getByPartNum(items[i].partnumber);
                    if (existingPart != null)
                    {
                        switch (existingPart.labortype)
                        {
                            case "Body":
                                items[i].laborcost = currEstimate.bodycost;
                                break;
                            case "Paint":
                                items[i].laborcost = currEstimate.paintcost;
                                break;
                            case "Frame":
                                items[i].laborcost = currEstimate.framecost;
                                break;
                            default:
                                items[i].laborcost = 100.00;
                                break;
                        }
                        if (items[i].qty == 0)
                        {
                            items[i].laborprice = items[i].labor * items[i].laborcost;
                        }
                        else
                        {
                            items[i].laborprice = items[i].labor * items[i].laborcost * items[i].qty;
                        }
                        items[i].extprice = items[i].partprice + items[i].laborprice;
                        _DAOFactory.EstimateItemsDAO.update(items[i]);
                    }
                }
                ViewBag.Success = "You have successfully changed your current estimates settings.";
            }
            if (isValid(id) == null)
            {
                return RedirectToAction("Home", "Account");
            }
            if (isValid(id) == "Admin")
            {
                ViewBag.UserPermission = "Admin";
            }
            else
            {
                ViewBag.UserPermission = _DAOFactory.EstimateValidationDAO.getByestIdUser(id, User.Identity.Name).permission;
            }
            return View(currEstimate);
        }