コード例 #1
0
        private static void SaveOptions(EditAttribute editAttribute, int attributeID)
        {
            var curList = AttributeOptions.GetByAttributeID(attributeID);

            foreach (var option in editAttribute.Options)
            {
                if (!curList.Any(item => item.ID == option.ID))
                {
                    var attributeOption = new AttributeOption();

                    attributeOption.AttributeID = attributeID;
                    attributeOption.Title       = option.Title;

                    AttributeOptions.Insert(attributeOption);
                }
                else
                {
                    var item = curList.Single(cls => cls.ID == option.ID);

                    curList.Remove(item);

                    item.Title   = option.Title;
                    item.OrderID = option.OrderID;

                    AttributeOptions.Update(item);
                }
            }

            foreach (var item in curList)
            {
                AttributeOptions.Delete(item.ID);
            }
        }
コード例 #2
0
        public ActionResult Edit(EditAttribute editAttribute)
        {
            try
            {
                var attribute = Mapper.Map <Attribute>(editAttribute);

                attribute.LastUpdate = DateTime.Now;

                ViewBag.Success = true;

                int attributeID = attribute.ID;
                if (attributeID == -1)
                {
                    Attributes.Insert(attribute);
                    attributeID = attribute.ID;

                    SaveGroups(editAttribute, attribute.ID);
                    SaveOptions(editAttribute, attribute.ID);

                    UserNotifications.Send(UserID, String.Format("جدید - ویژگی '{0}'", attribute.Title), "/Admin/Attributes/Edit/" + attribute.ID, NotificationType.Success);
                    editAttribute = new EditAttribute();
                }
                else
                {
                    Attributes.Update(attribute);

                    SaveGroups(editAttribute, attribute.ID);
                    SaveOptions(editAttribute, attribute.ID);

                    editAttribute.Groups  = AttributeGroups.GetByAttributeID(editAttribute.ID).Select(item => item.GroupID).ToList();
                    editAttribute.Options = AttributeOptions.GetByAttributeID(editAttribute.ID).Select(item => new EditAttributeOption()
                    {
                        ID = item.ID, AttributeID = item.AttributeID, Title = item.Title
                    }).ToList();
                }
            }
            catch (Exception ex)
            {
                SetErrors(ex);
            }

            return(ClearView(editAttribute));
        }
コード例 #3
0
        public JsonResult GetAttrOptions(int attrID)
        {
            var jsonSuccessResult = new JsonSuccessResult();

            try
            {
                var attrType = Attributes.GetByID(attrID).AttributeType;

                object model;

                if (attrType == AttributeType.SingleItem || attrType == AttributeType.MultipleItem)
                {
                    model = new
                    {
                        Options  = AttributeOptions.GetByAttributeID(attrID),
                        HasItems = true
                    };

                    jsonSuccessResult.Data = model;
                }
                else
                {
                    model = new
                    {
                        HasItems = false
                    };

                    jsonSuccessResult.Data = model;
                }

                jsonSuccessResult.Success = true;
            }
            catch (Exception ex)
            {
                jsonSuccessResult.Errors  = new string[] { ex.Message };
                jsonSuccessResult.Success = false;
            }

            return(new JsonResult()
            {
                Data = jsonSuccessResult
            });
        }