Exemple #1
0
        public ActionResult Edit(EditAttrGroup editAttrGroup)
        {
            try
            {
                var attrGroup = Mapper.Map <AttrGroup>(editAttrGroup);

                attrGroup.LastUpdate = DateTime.Now;

                ViewBag.Success = true;

                if (attrGroup.ID == -1)
                {
                    AttrGroups.Insert(attrGroup);

                    SaveGroups(editAttrGroup, attrGroup.ID);

                    UserNotifications.Send(UserID, String.Format("جدید - گروه ویژگی '{0}'", attrGroup.Title), "/Admin/AttrGroups/Edit/" + attrGroup.ID, NotificationType.Success);
                    editAttrGroup = new EditAttrGroup();
                }
                else
                {
                    AttrGroups.Update(attrGroup);

                    SaveGroups(editAttrGroup, attrGroup.ID);

                    editAttrGroup.Groups = AttrGroupGroups.GetByAttrGroupID(editAttrGroup.ID).Select(item => item.GroupID).ToList();
                }
            }
            catch (Exception ex)
            {
                SetErrors(ex);
            }

            return(ClearView(editAttrGroup));
        }
Exemple #2
0
        private static void SaveGroups(EditAttrGroup editAttrGroup, int attrGroupID)
        {
            var curList = AttrGroupGroups.GetByAttrGroupID(attrGroupID);

            foreach (var groupID in editAttrGroup.Groups)
            {
                if (!curList.Any(item => item.GroupID == groupID))
                {
                    var attrGroupGroup = new AttrGroupGroup();

                    attrGroupGroup.AttrGroupID = attrGroupID;
                    attrGroupGroup.GroupID     = groupID;

                    AttrGroupGroups.Insert(attrGroupGroup);
                }
                else
                {
                    curList.Remove(curList.Single(cls => cls.GroupID == groupID));
                }
            }

            foreach (var item in curList)
            {
                AttrGroupGroups.Delete(item.ID);
            }
        }
Exemple #3
0
        public ActionResult Edit(int?id)
        {
            EditAttrGroup editAttrGroup;

            if (id.HasValue)
            {
                editAttrGroup        = Mapper.Map <EditAttrGroup>(AttrGroups.GetByID(id.Value));
                editAttrGroup.Groups = AttrGroupGroups.GetByAttrGroupID(editAttrGroup.ID).Select(item => item.GroupID).ToList();
            }
            else
            {
                editAttrGroup = new EditAttrGroup();
            }

            return(View(editAttrGroup));
        }