// This method updates a Category record in the Warehouse database and returns true if the operation was successful.
        public bool Update_Category_By_ID(DataModel.Category category)
        {
            using (var context = new DataModel.WarehouseContext())
            {
                // Get and update Category
                bool success = false;
                var  cat     = context.Categories.SingleOrDefault(c => c.Category_ID == category.Category_ID);
                if (cat != null)
                {
                    cat.Category_Name        = category.Category_Name;
                    cat.Category_Description = category.Category_Description;

                    //Apply change
                    context.Categories.Attach(cat);
                    context.Entry(cat).State = System.Data.Entity.EntityState.Modified;
                }

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    success = false;
                }

                return(success);
            }
        }
        //Returns a Category given an ID
        public Category_BDO Get_Category_By_ID(int category_ID)
        {
            category_dto = category_query.Get_Category_By_ID(category_ID);

            Translate_DTO_to_BDO(category_BDO, category_dto);

            return(category_BDO);
        }
Ejemplo n.º 3
0
        private void CheckBeforeUpdate(DataModel.Category dbItem, Category category)
        {
            if (dbItem == null)
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.WasAlreadyDeleted, category.GetType().Name)
                      );
            }

            if (string.IsNullOrEmpty(category.Code))
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.ThePropertyCantBeEmpty, nameof(category.Code))
                      );
            }

            if (string.IsNullOrEmpty(category.DisplayName))
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.ThePropertyCantBeEmpty, nameof(category.DisplayName))
                      );
            }

            if (dbItem.Version != category.Version)
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.ItemWasAlreadyChanged, nameof(category))
                      );
            }

            if (dbItem.Code != category.Code && _context.Categories.Any(x => x.Code == category.Code))
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.PropertyDuplicate, "The category code")
                      );
            }
            if (dbItem.IsEverything && dbItem.IsEverything != category.IsEverything)
            {
                throw new InconsistencyException
                      (
                          Resources.TextMessages.CantDeleteSystemCategory
                      );
            }
            if (category.IsEverything && _context.Categories.Any(x => x.Id != category.Id && x.IsEverything))
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.MustBeOnlyOne, "System category ")
                      );
            }
        }
Ejemplo n.º 4
0
        public void tambah_kategori()
        {
            string idnya    = Guid.NewGuid().ToString();
            var    kategori = new DataModel.Category {
                Id = idnya, Name = "Apa Aja"
            };

            BusinessProcess.CategoryManager cm = new BusinessProcess.CategoryManager();
            cm.Add(kategori);
        }
Ejemplo n.º 5
0
        // PUT: api/APICategory/5
        public IEnumerable <string> Update(string id, [FromBody] DataModel.Category category)
        {
            BusinessProcess.CategoryManager cm = new BusinessProcess.CategoryManager();
            string idData = id.ToString();

            category = new DataModel.Category {
                Id = idData, Name = category.Name
            };
            var data = cm.Update(idData, category);

            return(new string[] { "info", data });
        }
Ejemplo n.º 6
0
        private void CheckBeforeDelete(DataModel.Category dbItem, Category category)
        {
            if (category.Id == null)
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.CantDeleteNewItem, category.GetType().Name)
                      );
            }

            if (dbItem == null)
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.WasAlreadyDeleted, category.GetType().Name)
                      );
            }

            if (dbItem.Version != category.Version)
            {
                throw new InconsistencyException
                      (
                          string.Format(Resources.TextMessages.ItemWasAlreadyChanged, category.GetType().Name)
                      );
            }

            if (dbItem.IsEverything)
            {
                throw new InconsistencyException(Resources.TextMessages.CantDeleteSystemCategory);
            }

            var catWithProjects = _context.CategoriesWithTotalProjects.FirstOrDefault(x => x.Id == category.Id);

            if (catWithProjects.TotalProjects > 0)
            {
                throw new InconsistencyException
                      (
                          string.Format
                          (
                              Resources.TextMessages.CantDeleteNotEmptyCategory,
                              catWithProjects.TotalProjects,
                              catWithProjects.DisplayName
                          )
                      );
            }
        }
Ejemplo n.º 7
0
 // POST: api/APICategory
 public IEnumerable <string> Post([FromBody] DataModel.Category category)
 {
     if (ModelState.IsValid)
     {
         BusinessProcess.CategoryManager cm = new BusinessProcess.CategoryManager();
         string idData = Guid.NewGuid().ToString();
         category = new DataModel.Category {
             Id = idData, Name = category.Name
         };
         var data = cm.Add(category);
         return(new string[] { "info", data });
     }
     else
     {
         return(new string[] { "info", "" });
     }
 }
        // This method retrieves a Category record in the Warehouse database using the category ID.
        public DataModel.Category Get_Category_By_ID(int category_id)
        {
            DataModel.Category category = new DataModel.Category();

            using (var context = new DataModel.WarehouseContext())
            {
                // Get product
                var cat = context.Categories.SingleOrDefault(c => c.Category_ID == category_id);
                if (cat != null)
                {
                    category.Category_ID          = cat.Category_ID;
                    category.Category_Name        = cat.Category_Name;
                    category.Category_Description = cat.Category_Description;

                    return(category);
                }
            }

            return(category);
        }
Ejemplo n.º 9
0
        public ActionResult GridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] DataModel.Category item)
        {
            var model = new object[0];

            if (ModelState.IsValid)
            {
                try
                {
                    // Insert here a code to insert the new item in your model
                }
                catch (Exception e)
                {
                    ViewData["EditError"] = e.Message;
                }
            }
            else
            {
                ViewData["EditError"] = "Please, correct all errors.";
            }
            return(PartialView("_GridViewPartial", model));
        }
Ejemplo n.º 10
0
        static private Core.Models.Category.CategoryItem Create(Core.Models.Category.CategoryItem category, DataModel.Entities db)
        {
            var newCategory = new DataModel.Category()
            {
                Id       = category.Id,
                Name     = category.Name,
                Url      = category.Url,
                Body     = category.Body,
                ParentId = category.ParentId,
                Row      = category.Row,
                UserId   = category.UserId,
                Language = category.Language,
                Type     = category.Type,
                Status   = category.Status,
                Created  = DateTime.Now
            };

            db.Categories.Add(newCategory);
            db.SaveChanges();
            return(category);
        }
        // This method deletes a Category record in the Warehouse database and returns true if the operation was successful.
        public bool Delete_Category_By_ID(int category_id)
        {
            using (var context = new DataModel.WarehouseContext())
            {
                // Delete the category using category ID
                bool success = false;
                DataModel.Category category = new DataModel.Category {
                    Category_ID = category_id
                };
                context.Categories.Attach(category);
                context.Categories.Remove(category);


                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result != 1)
                {
                    success = false;
                }

                return(success);
            }
        }
        // This method creates a Category record in the Warehouse database and returns true if the operation was successful.
        public bool Create(DataModel.Category category)
        {
            using (var context = new DataModel.WarehouseContext())
            {
                // Create and save a new Category

                DataModel.Category newCategory = new DataModel.Category();
                bool success = false;

                newCategory.Category_Description = category.Category_Description;
                newCategory.Category_Name        = category.Category_Name;

                context.Categories.Add(newCategory);

                //Check execution of transaction - we expect 1 change to have occurred
                var execution_result = context.SaveChanges();
                if (execution_result == 1)
                {
                    return(true);
                }

                return(success);
            }
        }
Ejemplo n.º 13
0
 static private Core.Models.Category.CategoryItem Update(Core.Models.Category.CategoryItem category, DataModel.Entities db, DataModel.Category dbCategory)
 {
     dbCategory.Name     = !string.IsNullOrEmpty(category.Name) && category.Name != dbCategory.Name ? category.Name : dbCategory.Name;
     dbCategory.Body     = !string.IsNullOrEmpty(category.Body) && category.Body != dbCategory.Body ? category.Body : dbCategory.Body;
     dbCategory.ParentId = category.ParentId != null && category.ParentId != dbCategory.ParentId ? category.ParentId : dbCategory.ParentId;
     dbCategory.Type     = category.Type != dbCategory.Type ? category.Type : dbCategory.Type;
     dbCategory.Status   = category.Status != dbCategory.Status ? category.Status : dbCategory.Status;
     dbCategory.Language = category.Language != dbCategory.Language ? category.Language : dbCategory.Language;
     db.SaveChanges();
     return(category);
 }
 //Translate data model object to BDO.
 private void Translate_DTO_to_BDO(Category_BDO category_BDO, DataModel.Category category_dto)
 {
     category_BDO.Category_ID          = category_dto.Category_ID;
     category_BDO.Category_Name        = category_dto.Category_Name;
     category_BDO.Category_Description = category_dto.Category_Description;
 }