示例#1
0
        public ActionResult Save(CategoryModel model)
        {
            Services.Category category;
            Int32             result;
            String            fileName;
            String            path;

            try {
                category             = new Services.Category();
                category.id          = model.id;
                category.Name        = model.Name;
                category.Description = model.Description;
                //category.Status = (Int32)CommonUnit.Status.Active;
                category.Status     = (Int32)model.Status;
                category.Type       = (Int32)model.Type;
                category.ImageUrl   = model.ImageUrl;
                category.CustomerId = SessionData.customer.id;
                if (model.Image != null)
                {
                    if (category.id == 0)
                    {
                        category.ImageUrl = Path.GetExtension(model.Image.FileName);
                    }
                    else
                    {
                        category.ImageUrl = String.Format("{0}{1}", model.id, Path.GetExtension(model.Image.FileName));
                    }
                }

                result = _categoryService.SaveCategory(category);
                if (result == 0)
                {
                    return(RedirectToAction("Index", "Error"));
                }

                fileName = (model.Image == null ? model.ImageUrl : model.Image.FileName);
                path     = Path.Combine(Server.MapPath("~/Images/Menus/"), SessionData.customer.id.ToString(), "Categories", String.Format("{0}{1}", result, Path.GetExtension(fileName)));
                if (model.Image == null && model.ImageUrl == null)
                {
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                }
                else if (model.Image != null)
                {
                    model.Image.SaveAs(path);
                }
            }
            catch (Exception ex) {
                base.Log(ex);
            }
            finally {
            }
            // Default menuDesigner
            return(RedirectToAction("Index", "Designer", new { id = (Int32)model.Type }));
        }
 public Boolean DeleteCategory(Int32? id) {
     Category query = new Category();
     id = id.HasValue ? id : 0;
     try {
         using (menuzRusDataContext db = new menuzRusDataContext(base.connectionString)) {
             query = db.Categories.Where(m => m.id == id).FirstOrDefault();
             if (query != default(Category)) {
                 query.Status = (Int32)Common.Status.NotActive;
                 db.SubmitChanges();
             }
         }
     }
     catch (Exception ex) {
         return false;
     }
     return true;
 }
        public ActionResult Save(CategoryModel model) {
            Services.Category category;
            Int32 result;
            String fileName;
            String path;

            try {
                category = new Services.Category();
                category.id = model.id;
                category.Name = model.Name;
                category.Description = model.Description;
                //category.Status = (Int32)Common.Status.Active;
                category.Status = (Int32)model.Status;
                category.Type = (Int32)model.Type;
                category.ImageUrl = model.ImageUrl;
                category.CustomerId = SessionData.customer.id;
                if (model.Image != null) {
                    if (category.id == 0)
                        category.ImageUrl = Path.GetExtension(model.Image.FileName);
                    else
                        category.ImageUrl = String.Format("{0}{1}", model.id, Path.GetExtension(model.Image.FileName));
                }

                result = _categoryService.SaveCategory(category);
                if (result == 0)
                    return RedirectToAction("Index", "Error");

                fileName = (model.Image == null ? model.ImageUrl : model.Image.FileName);
                path = Path.Combine(Server.MapPath("~/Images/Menus/"), SessionData.customer.id.ToString(), "Categories", String.Format("{0}{1}", result, Path.GetExtension(fileName)));
                if (model.Image == null && model.ImageUrl == null) {
                    if (System.IO.File.Exists(path))
                        System.IO.File.Delete(path);
                }
                else if (model.Image != null)
                    model.Image.SaveAs(path);
            }
            catch (Exception ex) {
                base.Log(ex);
            }
            finally {
            }
            // Default menuDesigner
            return RedirectToAction("Index", "Designer", new { id = (Int32)model.Type });
        }
 public Int32 SaveCategory(Category category) {
     Category query = new Category();
     try {
         using (menuzRusDataContext db = new menuzRusDataContext(base.connectionString)) {
             if (category.id != 0)
                 query = db.Categories.Where(m => m.id == category.id && m.Status != (Int32)Common.Status.NotActive).FirstOrDefault();
             if (query != default(Category)) {
                 query.Status = category.Status;
                 query.CustomerId = category.CustomerId;
                 query.Name = category.Name;
                 query.Description = category.Description;
                 query.ImageUrl = category.ImageUrl;
                 query.Type = category.Type;
             }
             if (category.id == 0) {
                 db.Categories.InsertOnSubmit(query);
             }
             db.SubmitChanges();
             // Update ImageName for new category
             if (category.id == 0 && query.ImageUrl != null) {
                 query.ImageUrl = String.Format("{0}{1}", query.id, category.ImageUrl);
                 db.SubmitChanges();
             }
         }
     }
     catch (Exception ex) {
         return 0;
     }
     return query.id;
 }
 public bool ValidateExist(Category _entity, List<Category> _objects, string _propertiesname, out string error)
 {
     return Service.ValidateExist(_entity, _objects, _propertiesname, out error);
 }
示例#6
0
 public int Insert(Category cat)
 {
     return(catRepo.Insert(cat));
 }
示例#7
0
 public int Update(Category cat)
 {
     return(catRepo.Update(cat));
 }
 public bool ValidateExist(Category _entity, List<Category> _objects, string _propertiesname,out string error)
 {
     var data = _entity.GetType().GetProperty(_propertiesname).GetValue(_entity, null);
        foreach (var item in _objects)
        {
        if (item.ID != _entity.ID)
        {
            if (item.GetType().GetProperty(_propertiesname).Name == _propertiesname)
            {
                if (item.GetType().GetProperty(_propertiesname).GetValue(item, null).ToString()==(data.ToString()))
                {
                    error = _propertiesname+ " bị trùng";
                    return true;
                }
            }
        }
        }
        error = "";
        return false;
 }
 partial void DeleteCategory(Category instance);
 partial void UpdateCategory(Category instance);
 partial void InsertCategory(Category instance);
		private void detach_Categories(Category entity)
		{
			this.SendPropertyChanging();
			entity.Customer = null;
		}