コード例 #1
0
 public ActionResult Edit(PresenterViewModel pvm)
 {
     pvm.Location.Company = db.FindCompany(pvm.Location.CompanyId);
     if (ModelState.IsValid)
     {
         db.Entry(pvm.Location).State = EntityState.Modified;
         pvm.Location.Phone           = GetNormalizedPhone(pvm.Phone);
         SavePresenters(pvm.Location.Id, pvm.contacts);
         db.SaveChanges();
         return(RedirectToAction("Index", new { companyId = pvm.Location.CompanyId }));
     }
     pvm.Location.Company = db.FindCompany(pvm.Location.CompanyId);
     return(View(pvm));
 }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "Id,Name,Phone,Email,CompanyID")] Client client)
 {
     if (ModelState.IsValid)
     {
         db.Entry(client).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { CompanyId = client.CompanyID }));
     }
     return(View(client));
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "Id,CompanyId,Name,Notes")] Collection collection)
 {
     if (ModelState.IsValid)
     {
         db.Entry(collection).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { CompanyId = collection.CompanyId }));
     }
     ViewBag.CompanyId = new SelectList(db.Companies, "Id", "Name", collection.CompanyId);
     return(View(collection));
 }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "Id,Name,CompanyId")] Shape shape)
 {
     if (ModelState.IsValid)
     {
         db.Entry(shape).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { shape.CompanyId }));
     }
     ViewBag.CompanyId   = shape.CompanyId;
     ViewBag.CompanyName = db._Companies.Find(shape.CompanyId)?.Name;
     return(View(shape));
 }
コード例 #5
0
 public ActionResult Edit([Bind(Include = "Id,Code,Desc,Market,Multiplier,CompanyId")] MetalCode metalCode)
 {
     if (ModelState.IsValid)
     {
         db.Entry(metalCode).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { metalCode.CompanyId }));
     }
     ViewBag.CompanyId   = metalCode.CompanyId;
     ViewBag.CompanyName = db._Companies.Find(metalCode.CompanyId)?.Name;
     return(View(metalCode));
 }
コード例 #6
0
 public ActionResult Edit(VendorViewModel vvm)
 {
     if (ModelState.IsValid)
     {
         Vendor vendor = new Vendor(vvm);
         db.Entry(vendor).State = EntityState.Modified;
         vendor.Phone           = GetNormalizedPhone(vvm.Phone);
         db.SaveChanges();
         return(RedirectToAction("Index", new { companyId = vendor.CompanyId }));
     }
     return(View(vvm));
 }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "Id,Name,PackagingCost,FinishingCost,CompanyId,bUseLaborTable")] JewelryType jewelryType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(jewelryType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { companyId = jewelryType.CompanyId }));
     }
     ViewBag.CompanyId      = jewelryType.CompanyId;
     ViewBag.CompanyName    = db._Companies.Find(jewelryType.CompanyId)?.Name;
     ViewBag.CompanyHasLTIs = db.LaborTable.Where(lti => lti.CompanyId == jewelryType.CompanyId).Count() == 0;
     return(View(jewelryType));
 }
コード例 #8
0
        public ActionResult Edit([Bind(Include = "Id,CompanyId,VendorId,Name,Desc,Price,Weight,Qty,Note")] Finding finding)
        {
            Finding existingFinding = db.Findings.Where(f => f.Id != finding.Id && f.CompanyId == finding.CompanyId && f.Name == finding.Name).FirstOrDefault();

            if (existingFinding != null)
            {
                ModelState.AddModelError("Name", $"A finding named '{finding.Name}' already exists. ");
            }
            if (ModelState.IsValid)
            {
                db.Entry(finding).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { companyId = finding.CompanyId }));
            }
            //ViewBag.MetalCodeId = new SelectList(db.MetalCodes, "Id", "Code", finding.MetalCodeId);
            ViewBag.VendorId    = new SelectList(db.Vendors.Where(v => v.CompanyId == finding.CompanyId && ((v.Type.Type & vendorTypeEnum.Finding) == vendorTypeEnum.Finding)), "Id", "Name", finding.VendorId);
            ViewBag.CompanyName = db._Companies.Find(finding.CompanyId)?.Name;
            return(View(finding));
        }
コード例 #9
0
        public ActionResult Edit([Bind(Include = "Id,CompanyId,VendorId,Name,Desc,CtWt,StoneSize,ShapeId,Price,Qty,SettingCost,Note,ParentHandle,Title,Label,Tags")] Stone stone)
        {
            stone.Name = stone.Name.Trim();
            // Don't allow an existing combo to be entered
            Stone extisingStone = db.Stones.Where(s => s.Id != stone.Id && s.CompanyId == stone.CompanyId && s.Name == stone.Name && s.StoneSize == stone.StoneSize && s.ShapeId == stone.ShapeId).FirstOrDefault();

            if (extisingStone != null)
            {
                Shape shape = db.Shapes.Find(stone.ShapeId);
                ModelState.AddModelError("Name", $"A stone with {stone.Name}/{stone.StoneSize}/{shape.Name} already exists. ");
            }
            if (ModelState.IsValid)
            {
                db.Entry(stone).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", new { companyId = stone.CompanyId }));
            }
            ViewBag.CompanyId   = stone.CompanyId;
            ViewBag.ShapeId     = new SelectList(db.Shapes.Where(s => s.CompanyId == stone.CompanyId), "Id", "Name", stone.ShapeId);
            ViewBag.VendorId    = new SelectList(db.Vendors.Where(v => v.CompanyId == stone.CompanyId && ((v.Type.Type & vendorTypeEnum.Stone) == vendorTypeEnum.Stone)), "Id", "Name", stone.VendorId);
            ViewBag.CompanyName = db._Companies.Find(stone.CompanyId)?.Name;

            return(View(stone));
        }
コード例 #10
0
        public async Task <ActionResult> Edit(StyleViewModel svm)
        {
            CheckForNameAndNumberUniqueness(svm);
            int i;

            // Check special cases in Model
            CheckModelState(svm);
            //
            TraceModelStateErrors(svm.Style.StyleName);
            // Save the Style and all edited components; add the new ones and remove the deleted ones
            if (ModelState.IsValid)
            {
                bool bUseLaborTable = svm.Style.JewelryType.bUseLaborTable;
                svm.Style.JewelryType = null; // hack to avoid maismatch of JewelryTypeId error!!!

                if (db.Entry(svm.Style).State != EntityState.Added)
                {
                    db.Entry(svm.Style).State = EntityState.Modified;
                }
                // Iterate thru the components
                // Castings
                if (svm.Castings != null)
                {
                    i = -1;
                    foreach (CastingComponent c in svm.Castings)
                    {
                        i++;
                        Casting      casting;
                        StyleCasting sc;
                        try
                        {
                            ValidCasting(c);
                        }
                        catch (OjMissingCastingException e)
                        {
                            ModelState.AddModelError("Castings[" + i + "].Name", e.Message);
                            continue;
                        }

                        switch (c.State)
                        {
                        case SVMStateEnum.Added:
                            casting = new Casting(c);
                            // add a new link
                            casting.Id = -i;
                            db.Castings.Add(casting);
                            sc = new StyleCasting()
                            {
                                CastingId = casting.Id,
                                StyleId   = svm.Style.Id,
                            };
                            db.StyleCastings.Add(sc);
                            break;

                        case SVMStateEnum.Deleted:
                            sc = db.StyleCastings.Where(x => x.StyleId == svm.Style.Id && x.CastingId == c.Id)
                                 .SingleOrDefault();
                            casting = db.Castings.Find(c.Id);
                            db.Castings.Remove(casting);
                            db.StyleCastings.Remove(sc);
                            break;

                        case SVMStateEnum.Dirty:
                        case SVMStateEnum.Fixed:
                            casting = db.Castings.Find(c.Id);
                            casting.Set(c);

                            /*
                             * // Update the Syle-Casting Link
                             * sc = db.StyleCastings.Where(x => x.StyleId == svm.Style.Id && x.CastingId == c.Id).SingleOrDefault();
                             */
                            break;

                        case SVMStateEnum.Unadded:
                            break;

                        default:
                            break;
                        }
                    }
                }
                // Stones
                if (svm.Stones != null)
                {
                    i = -1;
                    foreach (StoneComponent sc in svm.Stones)
                    {
                        i++;
                        //Stone stone;
                        StyleStone ss;
                        int        stoneId = 0;
                        try
                        {
                            stoneId = ValidStone(svm.CompanyId, sc);
                            sc.Id   = stoneId;
                        }
                        catch (OjInvalidStoneComboException e)
                        {
                            ModelState.AddModelError("Stones[" + i + "].Name", e.Message);
                            continue;
                        }
                        catch (OjMissingStoneException)
                        {
                            if (sc.Name == null)
                            {
                                ModelState.AddModelError("Stones[" + i + "].Name", "You must enter a stone!! ");
                            }
                            if (sc.ShId == null)
                            {
                                ModelState.AddModelError("Stones[" + i + "].ShId", "You must enter a shape!! ");
                            }
                            if (sc.SzId == null)
                            {
                                ModelState.AddModelError("Stones[" + i + "].SzId", "You must enter a size!! ");
                            }
                            continue;
                        }

                        switch (sc.State)
                        {
                        case SVMStateEnum.Added:
                            //stone = new Stone(sc);
                            //db.Stones.Add(stone);
                            ss = new StyleStone()
                            {
                                StyleId = svm.Style.Id,
                                StoneId = stoneId,
                                Qty     = (int)sc.Qty
                            };
                            db.StyleStones.Add(ss);
                            break;

                        case SVMStateEnum.Deleted:
                            ss = db.StyleStones.Where(x => x.Id == sc.linkId).SingleOrDefault();
                            //db.Stones.Remove(ss.Stone);
                            db.StyleStones.Remove(ss);
                            break;

                        case SVMStateEnum.Dirty:
                        case SVMStateEnum.Fixed:
                            //stone = db.Stones.Find(sc.Id);
                            //stone.Set(sc);
                            ss = db.StyleStones.Where(x => x.Id == sc.linkId).SingleOrDefault();
                            //ss = db.StyleStones.Where(x => x.StyleId == svm.Style.Id && x.Id == sc.Id).SingleOrDefault();
                            ss.Qty     = (int)sc.Qty;
                            ss.StoneId = stoneId;
                            break;

                        case SVMStateEnum.Unadded:
                        default:
                            break;
                        }
                    }
                }
                // Findings
                if (svm.Findings != null)
                {
                    i = -1;
                    foreach (FindingsComponent c in svm.Findings)
                    {
                        i++;
                        StyleFinding fc;
                        try
                        {
                            ValidFinding(c, i);
                        }
                        catch (OjMissingFindingException e)
                        {
                            ModelState.AddModelError("Findings[" + i + "].Id", e.Message);
                            continue;
                        }
                        switch (c.State)
                        {
                        case SVMStateEnum.Added:
                            /*
                             * component = new Component(c);
                             * db.Components.Add(component);
                             */
                            fc = new StyleFinding()
                            {
                                StyleId   = svm.Style.Id,
                                FindingId = c.Id ?? 0,
                                Qty       = c.Qty
                            };

                            db.StyleFindings.Add(fc);
                            break;

                        case SVMStateEnum.Deleted:
                            fc = db.StyleFindings.Where(x => x.Id == c.linkId).SingleOrDefault();
                            //db.Findings.Remove(fc.Finding);
                            db.StyleFindings.Remove(fc);
                            break;

                        case SVMStateEnum.Dirty:
                        case SVMStateEnum.Fixed:
                            /*
                             * component = db.Components.Find(c.Id);
                             * component.Set(c);
                             */
                            //finding.Set(c); // Dont change the finding, just the link!!!
                            fc           = db.StyleFindings.Where(x => x.Id == c.linkId).SingleOrDefault();
                            fc.FindingId = c.Id ?? 0;
                            fc.Qty       = c.Qty;
                            break;

                        case SVMStateEnum.Unadded:     // No updates
                        default:
                            break;
                        }
                    }
                }
                // Labors
                if (svm.Labors != null && bUseLaborTable == false)
                {
                    i = -1;
                    foreach (LaborComponent lc in svm.Labors)
                    {
                        i++;
                        Labor      labor;
                        StyleLabor sl;
                        try
                        {
                            ValidLabor(lc);
                        }
                        catch (OjMissingLaborException e)
                        {
                            ModelState.AddModelError("Labors[" + i + "].Name", e.Message);
                            continue;
                        }

                        switch (lc.State)
                        {
                        case LMState.Added:
                            AddLabor(lc, svm, i);
                            break;

                        case LMState.Deleted:
                            sl = db.StyleLabors.Where(x => x.StyleId == svm.Style.Id && x.LaborId == lc.Id).Single();
                            RemoveLabor(sl);
                            break;

                        case LMState.Fixed:
                        case LMState.Dirty:
                            if (lc.Id <= 0)
                            {
                                AddLabor(lc, svm, i);
                            }
                            else
                            {
                                labor = db.Labors.Find(lc.Id);
                                labor.Set(lc);
                            }

                            /*
                             * sl = db.StyleLabors.Where(x => x.StyleId == svm.Style.Id && x.LaborId == c.Id).Single();
                             */
                            break;

                        case LMState.Unadded:     // No updates
                        default:
                            break;
                        }
                    }
                }
                // Labor Table
                if (svm.LaborItems != null && bUseLaborTable == true)
                {
                    i = -1;
                    foreach (LaborItemComponent lic in svm.LaborItems)
                    {
                        i++;
                        StyleLaborTableItem sl;
                        try
                        {
                            ValidLaborItem(lic);
                        }
                        catch (OjMissingLaborException e)
                        {
                            ModelState.AddModelError("LaborsItems[" + i + "].Name", e.Message);
                            continue;
                        }

                        switch (lic.State)
                        {
                        case LMState.Added:
                            AddLaborItem(lic, svm, i);
                            break;

                        case LMState.Deleted:
                            sl = db.StyleLaborItems.Where(x => x.Id == lic.linkId).SingleOrDefault();
                            RemoveLaborItem(sl);
                            break;

                        case LMState.Dirty:
                        case LMState.Fixed:
                            if (lic.Id <= 0)
                            {
                                AddLaborItem(lic, svm, i);
                            }
                            else
                            {
                                //laborItem = db.LaborTable.Find(lic.laborItemId);
                                sl              = db.StyleLaborItems.Where(x => x.Id == lic.linkId).SingleOrDefault();
                                sl.Qty          = lic.Qty.GetValueOrDefault();
                                sl.LaborTableId = lic.laborItemId.GetValueOrDefault();
                                //laborItem.Set(lic);
                            }

                            /*
                             * sl = db.StyleLabors.Where(x => x.StyleId == svm.Style.Id && x.LaborId == c.Id).Single();
                             */
                            break;

                        case LMState.Unadded:     // No updates
                        default:
                            break;
                        }
                        db.Entry(lic._laborItem).State = EntityState.Detached;
                    }
                }

                // Misc
                if (svm.Miscs != null)
                {
                    Misc      misc;
                    StyleMisc sm;
                    i = -1;
                    foreach (MiscComponent c in svm.Miscs)
                    {
                        i++;
                        try
                        {
                            ValidMisc(c);
                        }
                        catch (OjMissingMiscException e)
                        {
                            ModelState.AddModelError("Miscs[" + i + "].Name", e.Message);
                            continue;
                        }

                        switch (c.State)
                        {
                        case SVMStateEnum.Added:
                            AddMisc(c, svm, i);
                            break;

                        case SVMStateEnum.Deleted:
                            sm = db.StyleMiscs.Where(x => x.StyleId == svm.Style.Id && x.MiscId == c.Id).Single();
                            RemoveMisc(sm);
                            break;

                        case SVMStateEnum.Dirty:
                        case SVMStateEnum.Fixed:
                            if (c.Id <= 0)
                            {
                                AddMisc(c, svm, i);
                            }
                            else
                            {
                                misc = db.Miscs.Find(c.Id);
                                misc.Set(c);
                            }

                            /*
                             * sm = db.StyleMiscs.Where(x => x.StyleId == svm.Style.Id && x.MiscId == c.Id).Single();
                             */
                            break;

                        case SVMStateEnum.Unadded:     // No updates
                        default:
                            break;
                        }
                    }

                    if (svm.SVMState == SVMStateEnum.Added)
                    {
                        db.Styles.Add(svm.Style);
                    }
                } // false
            }
            if (ModelState.IsValid)
            {
                if (true) // if the modelstate only has validation errors on "Clean" components, then allow the DB update
                {
                    // Save changes, go to Home
                    try
                    {
                        db.SaveChanges(); // need the styleId for the image name
                    }
                    catch (Exception e)
                    {
                        Trace.TraceError($"Error saving style {svm.Style.StyleName}, msg: {e.Message}");
                    }
                    Trace.TraceInformation("Operation: {0}, svmId:{1}", svm.SVMOp.ToString(), svm.Style.Id);
                    await SaveImageInStorage(db, svm);

                    db.Entry(svm.Style);
                    db.SaveChanges();
                    if (svm.SVMOp == SVMOperation.Create)
                    {
                        // Redurect to Edit
                        return(RedirectToAction("Edit", new { id = svm.Style.Id }));
                    }
                    if (svm.SVMOp != SVMOperation.Print)
                    {
                        // Redurect to Edit
                        return(RedirectToAction("Index", new { CollectionId = svm.Style.CollectionId }));
                    }
                    else
                    {
                        return(Print(svm.Style.Id));
                    }
                }
            }
            Collection co = db.Collections.Find(svm.Style.CollectionId);

            svm.CompanyId         = co.CompanyId;
            svm.Style.JewelryType = db.JewelryTypes.Find(svm.Style.JewelryTypeId);

            //svm.Style.
            string markup = db.FindCompany(svm.CompanyId).markup;

            if (markup == null)
            {
                markup = "[]";
            }
            svm.markups = JsonConvert.DeserializeObject <List <Markup> >(markup);
            svm.PopulateDropDownData(db);
            svm.PopulateDropDowns(db);
            if (svm.SVMOp == SVMOperation.Create)
            {
                svm.LookupComponents(db);
            }
            else
            {
                svm.RepopulateComponents(db); // iterate thru the data and repopulate the links
            }
            ViewBag.CollectionId = new SelectList(db.Collections.Where(x => x.CompanyId == co.CompanyId), "Id", "Name", svm.Style.CollectionId);
            //ViewBag.JewelryTypeId = new SelectList(db.JewelryTypes.Where(x => x.CompanyId == co.CompanyId), "Id", "Name", svm.Style.JewelryTypeId);
            ViewBag.MetalWtUnitId = new SelectList(db.MetalWeightUnits.OrderBy(mwu => mwu.Unit), "Id", "Unit", svm.Style.MetalWtUnitId);
            // iterate thru modelstate errors, display on page
            return(View(svm));
        }
コード例 #11
0
        public ActionResult Index(LaborTableModel ltm)
        {
            List <Vendor> vendors;

            if (ModelState.IsValid)
            {
                int i = -1;
                //db.Entry(cvm.company).State = EntityState.Modified;

                foreach (LaborItem li in ltm.Labors)
                {
                    i++;
                    switch (li.State)
                    {
                    case LMState.Added:
                        li.CompanyId = ltm.CompanyId;
                        db.LaborTable.Add(li);
                        li.State = LMState.Dirty;
                        break;

                    case LMState.Deleted:
                        // Make sure its not used. If it is, reset to "Dirty" and add an error message
                        if (db.StyleLaborItems.Where(sli => sli.LaborTableId == li.Id).Count() > 0)
                        {
                            li.State = LMState.Dirty;
                            ModelState.SetModelValue($"Labors[{i}].State", new ValueProviderResult("Dirty", "", System.Globalization.CultureInfo.InvariantCulture));
                            ModelState.AddModelError($"Labors[{i}].Name", $"You cannot delete {li.Name}: it is used by the following style(s):{StylesInUse(li)}");
                            break;
                        }
                        db.Entry(li).State = EntityState.Deleted;
                        db.LaborTable.Remove(li);
                        break;

                    case LMState.Dirty:
                        db.Entry(li).State = EntityState.Modified;
                        break;

                    case LMState.Unadded:
                    case LMState.Clean:
                    case LMState.Fixed:
                        break;
                    }
                }
            }
            vendors = db.Vendors.Where(v => v.CompanyId == ltm.CompanyId).ToList();
            if (ModelState.IsValid)
            {
                db.SaveChanges();

                int    CompanyId   = ltm.CompanyId;
                string CompanyName = ltm.CompanyName;

                ModelState.Clear();
                ltm = new LaborTableModel()
                {
                    Labors      = db.LaborTable.Where(l => l.CompanyId == CompanyId).ToList(),
                    CompanyId   = CompanyId,
                    CompanyName = CompanyName,
                };
                foreach (LaborItem li in ltm.Labors)
                {
                    li.selectList = new SelectList(vendors, "Id", "Name", li.VendorId);
                }
                ltm.bHasVendors = vendors.Count != 0;
                return(RedirectToAction("Index", "Companies"));
            }
            foreach (LaborItem li in ltm.Labors)
            {
                li.selectList = new SelectList(vendors, "Id", "Name", li.VendorId);
            }
            ltm.bHasVendors = vendors.Count != 0;
            return(View(ltm));
        }