Пример #1
0
 private ActionResult Sync(FinalEstimateVM estimate,int id)
 {
     for (int i = 0; i < estimate.Items.Count; i++)
     {
         var part = _DAOFactory.PartsDAO.getByPartNum(estimate.Items[i].partnumber);
         if (part != null)
         {
             int job = estimate.Items[i].job;
             estimate.Items[i] = PartToItem(part, estimate.Items[i].qty, estimate.Estimate.estid);
             estimate.Items[i].job = job;
             _AddUpdate.addUpdateEstimateItem(estimate.Items[i]);
         }
     }
     return View("Estimate", estimate);
 }
Пример #2
0
 public ActionResult Estimate(string EstimateSave, FinalEstimateVM finalEstimate, int id, FormCollection collection)
 {
     if (isValid(id) == null)
     {
         return RedirectToAction("Home", "Account");
     }
     ModelState.Clear();
     if (finalEstimate.Notes == null)
     {
         finalEstimate.Notes = new List<notes>();
     }
     if (finalEstimate.Items == null)
     {
         finalEstimate.Items = new List<estimateitems>();
     }
     else
     {
         for (int i = 0; i < finalEstimate.Items.Count; i++)
         {
             for (int j = 0; j < finalEstimate.Items.Count; j++)
             {
                 if (i != j)
                 {
                     if (finalEstimate.Items[i].partnumber == finalEstimate.Items[j].partnumber &&
                         finalEstimate.Items[i].job == finalEstimate.Items[j].job)
                     {
                         finalEstimate.Items = new List<estimateitems>();
                         foreach (var item in _DAOFactory.EstimateItemsDAO.getByEstId(id))
                         {
                             finalEstimate.Items.Add(item);
                         }
                         ModelState.AddModelError("PartError", "Parts with the same part number in your cart must have a different job number");
                         return View(finalEstimate);
                     }
                 }
             }
         }
     }
     switch (EstimateSave)
     {
         case "Save":
             return Save(finalEstimate, id);
         default:
             return Sync(finalEstimate, id);
     }
 }
Пример #3
0
        private ActionResult Save(FinalEstimateVM estimate,int id)
        {
            if (_DAOFactory.EstimateDAO.getById(id) != null)
            {
                estimate.Estimate.isopen = true;
                _DAOFactory.EstimateDAO.update(estimate.Estimate);
            }
            if (estimate.Owner != null)
            {
                estimate.Owner.estid = id;
                _AddUpdate.addUpdateOwner(estimate.Owner);
            }
            if (estimate.Finance != null)
            {
                estimate.Finance.estid = id;
                _AddUpdate.addUpdateFinance(estimate.Finance);
            }
            estimate.Insurance.estid = id;
            _AddUpdate.addUpdateInsurance(estimate.Insurance);

            estimate.Claim.estid = id;
            _AddUpdate.addUpdateClaim(estimate.Claim);

            estimate.EstimateVehicle.estid = id;
            _AddUpdate.addUpdateVehicle(estimate.EstimateVehicle);
            for (int i = 0; i < estimate.Items.Count; i++)
            {
                estimate.Items[i].estid = id;
                if (estimate.Items[i].description == "Delete From Estimate")
                {
                    _DAOFactory.EstimateItemsDAO.delete(estimate.Items[i]);
                    estimate.Items.RemoveAt(i);
                    i--;
                }
                else
                {
                    try
                    {
                        if (estimate.Items[i].qty == 0)
                        {
                            estimate.Items[i].totallabor = estimate.Items[i].labor;
                            estimate.Items[i].laborprice = estimate.Items[i].totallabor * estimate.Items[i].laborcost;
                        }
                        else
                        {
                            estimate.Items[i].totallabor = estimate.Items[i].labor * estimate.Items[i].qty;
                            estimate.Items[i].laborprice = estimate.Items[i].totallabor * estimate.Items[i].laborcost;
                        }
                        estimate.Items[i].partprice = estimate.Items[i].partcost * estimate.Items[i].qty;
                        estimate.Items[i].extprice = estimate.Items[i].laborprice + estimate.Items[i].partprice;
                        _AddUpdate.addUpdateEstimateItem(estimate.Items[i]);
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("PartError", "Please Enter a valid Part Number and Job Number");
                        return View("Estimate", estimate);
                    }
                }
            }
            for (int i = 0; i < estimate.Notes.Count; i++)
            {
                estimate.Notes[i].estid = id;
                if (estimate.Notes[i].description == null || estimate.Notes[i].description == "")
                {
                    if (estimate.Notes[i].id != 0)
                    {
                        _DAOFactory.NotesDAO.delete(estimate.Notes[i]);
                    }
                    estimate.Notes.RemoveAt(i);
                    i--;
                }
                else
                {
                    try
                    {
                        _AddUpdate.addUpdateEstimateNote(estimate.Notes[i]);
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("NoteError", "There has been an error saving your notes");
                        return View("Estimate", estimate);
                    }
                }
            }
            return View("Estimate", estimate);
        }
Пример #4
0
 public ActionResult Estimate(int id)
 {
     if (isValid(id) == null)
     {
         return RedirectToAction("Home", "Account");
     }
     FinalEstimateVM finalEstimate = new FinalEstimateVM();
     finalEstimate.Estimate = _DAOFactory.EstimateDAO.getById(id);
     finalEstimate.Owner = _DAOFactory.OwnerDAO.getById(id);
     finalEstimate.Finance = _DAOFactory.FinanceDAO.getById(id);
     var insurance = _DAOFactory.InsuranceDAO.getById(id);
     finalEstimate.Insurance = insurance != null ? insurance : new insurance();
     var insured = _DAOFactory.InsuredDAO.getById(id);
     finalEstimate.Insured = insured != null ? insured : new insured();
     var claim = _DAOFactory.ClaimDAO.getByEstId(id);
     finalEstimate.Claim = claim != null ? claim : new claim();
     var vehicle = _DAOFactory.EstimateVehicleDAO.getById(id);
     finalEstimate.EstimateVehicle = vehicle != null ? vehicle : new estimatevehicle();
     finalEstimate.Items = new List<estimateitems>();
     foreach (var item in _DAOFactory.EstimateItemsDAO.getByEstId(id))
     {
         finalEstimate.Items.Add(item);
     }
     finalEstimate.Notes = new List<notes>();
     foreach (var note in _DAOFactory.NotesDAO.getByEstId(id))
     {
         finalEstimate.Notes.Add(note);
     }
     return View(finalEstimate);
 }