Beispiel #1
0
        public ActionResult Create(Element entity, ICollection <ElementCulture> elementCulture, ICollection <AttributeExtended> elementAttribute)
        {
            //if (!ModelState.IsValid)
            //{
            //    var errors = ModelState.Values.Where(p => p.Errors.Count > 0).ToList();
            //    this.LoadViewBagData(entity);
            //    return View();
            //}
            //else
            //{
            IList <ElementAttribute> selectedAttributes = null;

            if (elementAttribute != null)
            {
                selectedAttributes = (from ea in elementAttribute
                                      where ea.Checked == true
                                      select new ElementAttribute
                {
                    IDAttribute = ea.IDAttribute.Value,
                    Value = ea.Value
                }).ToList();
            }

            if (!entity.IDElement.HasValue)
            {
                entity.IDCustomer = SiteContext.GetActiveProfile.Preferences.IDCustomer;
                entity.CreateDate = DateTime.Now;
                entity.CreatedBy  = SiteContext.ActiveUserName;
                entity.ModifyDate = DateTime.Now;
                entity.ModifiedBy = SiteContext.ActiveUserName;
                ServiceContext.ElementService.Insert(entity, elementCulture, selectedAttributes);
                Session["IDElement"] = entity.IDElement.Value;
                //Copia as imagens do diretorio temporario para o novo com a sessão
                IOHelper.CopyFiles(Server.MapPath(this.TemporaryImageBasePath()), Server.MapPath(this.ImageBasePath()), true);

                //Setando a imagem principal
                Services.ServiceContext.ElementService.ChangeDefaultImage(entity.IDElement.Value, this.DefaultPicturePath(entity.IDCustomer, entity.IDElement.Value));
                this.TempData["Message"] = Internationalization.Message.Record_Inserted_Successfully;
            }
            else
            {
                entity.DefaultPicturePath = this.DefaultPicturePath(entity.IDCustomer, entity.IDElement.Value);
                entity.ModifyDate         = DateTime.Now;
                entity.ModifiedBy         = SiteContext.ActiveUserName;
                ServiceContext.ElementService.Update(entity, elementCulture, selectedAttributes);
                this.TempData["Message"] = Internationalization.Message.Record_Updated_Successfully;
            }
            this.LoadViewBagData(entity);
            return(RedirectToAction("create", new { id = entity.IDElement.Value }));
            //}
        }