Ejemplo n.º 1
0
        public ActionResult Edit(Guid id, Guid?versionId)
        {
            try
            {
                var material = entityService.Get <Material>(id, null, a => a.ClassConceptKey == EntityClassKeys.Material);

                if (material == null)
                {
                    TempData["error"] = Locale.MaterialNotFound;

                    return(RedirectToAction("Index"));
                }

                if (material.Tags.Any(t => t.TagKey == Constants.ImportedDataTag && t.Value?.ToLower() == "true"))
                {
                    this.TempData["warning"] = Locale.RecordMustBeVerifiedBeforeEditing;
                    return(RedirectToAction("ViewMaterial", new { id, versionId }));
                }

                var formConcepts     = this.materialConceptService.GetFormConcepts();
                var quantityConcepts = this.materialConceptService.GetQuantityConcepts();
                var typeConcepts     = this.materialConceptService.GetMaterialTypeConcepts();

                var relationships = new List <EntityRelationship>();

                relationships.AddRange(this.entityService.GetEntityRelationships <Material>(material.Key.Value, r => r.RelationshipTypeKey == EntityRelationshipTypeKeys.UsedEntity && r.ObsoleteVersionSequenceId == null).ToList());
                relationships.AddRange(this.entityService.GetEntityRelationships <ManufacturedMaterial>(material.Key.Value, r => r.RelationshipTypeKey == EntityRelationshipTypeKeys.Instance && r.ObsoleteVersionSequenceId == null).ToList());

                material.Relationships = relationships.Intersect(material.Relationships, new EntityRelationshipComparer()).ToList();

                var model = new EditMaterialModel(material)
                {
                    FormConcepts     = formConcepts.ToSelectList(this.HttpContext.GetCurrentLanguage(), c => c.Key == material.FormConceptKey).ToList(),
                    QuantityConcepts = quantityConcepts.ToSelectList(this.HttpContext.GetCurrentLanguage(), c => c.Key == material.QuantityConceptKey).ToList(),
                    TypeConcepts     = typeConcepts.ToSelectList(this.HttpContext.GetCurrentLanguage(), c => c.Key == material.TypeConceptKey).ToList(),
                    UpdatedBy        = this.userService.GetUserEntityBySecurityUserKey(material.CreatedByKey.Value)?.GetFullName(NameUseKeys.OfficialRecord)
                };

                return(View(model));
            }
            catch (Exception e)
            {
                this.TempData["error"] = Locale.UnexpectedErrorMessage;
                Trace.TraceError($"Unable to retrieve material: {e}");
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
 public ActionResult EditMaterial(EditMaterialModel model)
 {
     if (ModelState.IsValid)
     {
         MeasureMaterial mm = db.MeasureMaterials.Find(model.MeasureMaterialId);
         if (mm != null)
         {
             mm.MaterialTypeId     = model.MaterialTypeId.Value;
             mm.AltWidthId         = model.AltWidthId;
             mm.WidthId            = model.WidthId;
             mm.Description        = model.Description;
             mm.PatternMatchWidth  = model.PatternWidth;
             mm.PatternMatchLength = model.PatternLength;
             int c = db.SaveChanges();
             return(RedirectToAction("Details/" + mm.MeasureId.ToString()));
         }
     }
     model.MaterialTypeList = db.MaterialTypes.ToList().Select(i => new Lookup(i.Id, i.Description)).ToList();
     model.WidthList        = db.Widths.ToList();
     return(View(model));
 }
Ejemplo n.º 3
0
        public ActionResult EditMaterial(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EditMaterialModel model = new EditMaterialModel();

            MeasureMaterial mm = db.MeasureMaterials.Find(id);

            model.MeasureMaterialId = id.Value;
            model.AltWidthId        = mm.AltWidthId;
            model.Description       = mm.Description;
            model.MaterialTypeId    = mm.MaterialTypeId;
            model.PatternLength     = mm.PatternMatchLength;
            model.PatternWidth      = mm.PatternMatchWidth;
            model.WidthId           = mm.WidthId;
            model.MaterialTypeList  = db.MaterialTypes.ToList().Select(i => new Lookup(i.Id, i.Description)).ToList();
            model.WidthList         = db.Widths.ToList();
            model.MeasureId         = mm.MeasureId;
            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult Edit(EditMaterialModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var material = this.entityService.Get <Material>(model.Id, model.VersionKey, m => m.ClassConceptKey == EntityClassKeys.Material && m.ObsoletionTime == null);

                    if (material == null)
                    {
                        TempData["error"] = Locale.MaterialNotFound;

                        return(RedirectToAction("Index"));
                    }

                    var materialToUpdate = model.ToMaterial(material);

                    materialToUpdate.CreatedByKey = Guid.Parse(this.User.Identity.GetUserId());

                    var updatedEntity = this.entityService.Update(materialToUpdate);

                    TempData["success"] = Locale.MaterialUpdatedSuccessfully;

                    return(RedirectToAction("ViewMaterial", new { id = updatedEntity.Key, versionId = updatedEntity.VersionKey }));
                }
            }
            catch (Exception e)
            {
                Trace.TraceError($"Unable to update material: {e}");
            }
            finally
            {
                MvcApplication.MemoryCache.Remove(model.Id.ToString());
            }

            TempData["error"] = Locale.UnableToUpdateMaterial;

            return(View(model));
        }