public static async Task RemovePartFromCategory()
        {
            DbContextOptionsBuilder <ManufacturingContext> optionsBuilder = new DbContextOptionsBuilder <ManufacturingContext>();

            optionsBuilder.UseSqlServer("server=192.168.0.5;database=manufacturing_inventory_dev;user=aelmendorf;password=Drizzle123!;MultipleActiveResultSets=true");

            using var context = new ManufacturingContext(optionsBuilder.Options);
            Console.WriteLine("Working, Please Wait...");
            CategoryEdit categoryService = new CategoryEdit(context);
            var          categories      = await categoryService.GetCategories();

            var category = categories.FirstOrDefault(e => e.Id == 14);
            //var instance=category
            var partInstances = await categoryService.GetCategoryPartInstances(category);

            var partInstance = partInstances.FirstOrDefault(e => e.Id == 1);
            var output       = await categoryService.RemovePartFrom(partInstance.Id, category);

            if (output.Success)
            {
                Console.WriteLine(output.Message);
            }
            else
            {
                Console.WriteLine(output.Message);
            }
        }
        public ActionResult Edit(int id, CategoryEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.CategoryId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateCategoryService();

            if (service.UpdateCategory(model))
            {
                TempData["SaveResult"] = "Your category was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your category could not be updated.");

            return(View(model));
        }
Exemple #3
0
        public ActionResult EditCategory(int id)
        {
            CategoryEdit category = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44320/api/");
                string token = DeserializeToken();
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
                var responseTask = client.GetAsync("category/" + id.ToString());
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <CategoryEdit>();
                    readTask.Wait();

                    category = readTask.Result;
                }
                else
                {
                    ModelState.AddModelError(string.Empty, result.Content.ReadAsStringAsync().Result);
                }
            }

            return(View(category));
        }
Exemple #4
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var service = CreateCategoryService();

            try
            {
                var detail = service.GetCategoryById(id.Value);

                var model = new CategoryEdit
                {
                    CategoryId = detail.CategoryId,
                    Name       = detail.Name
                };

                return(View(model));
            }
            catch (Exception)
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
Exemple #5
0
        public bool UpdateCategory(CategoryEdit model)
        {
            try
            {
                using (var ctx = new ApplicationDbContext())
                {
                    var categoryEntity = ctx.Categories.Where(c => c.Id == model.Id)
                                         .FirstOrDefault();
                    if (categoryEntity == null)
                    {
                        return(false);
                    }

                    categoryEntity.Name        = model.Name;
                    categoryEntity.Description = model.Description;
                    categoryEntity.ModifiedAt  = DateTimeOffset.UtcNow;

                    return(ctx.SaveChanges() == 1);
                }
            }
            catch (Exception e)
            {
                SentrySdk.CaptureException(e);
                return(false);
            }
        }
 public IActionResult Edit(string id)
 {
     try
     {
         var category = categoryRepository.Get(int.Parse(id));
         if (category != null && !category.IsDelete)
         {
             var editcategory = new CategoryEdit()
             {
                 ImagePath    = category.ImagePath,
                 CategoryName = category.CategoryName,
                 CategoryId   = category.CategoryId,
                 Status       = category.Status
             };
             return(View(editcategory));
         }
         else
         {
             ViewBag.id = id;
             return(View("~/Views/Error/CategoryNotFound.cshtml"));
         }
     }
     catch (Exception)
     {
         ViewBag.id = id;
         return(View("~/Views/Error/CategoryNotFound.cshtml"));
     }
 }
Exemple #7
0
 public CategoryEditViewModel(CategoryEdit category)
     : this()
 {
     Id          = category.Id;
     NameSlovak  = category.Name.Slovak;
     NameEnglish = category.Name.English;
     Order       = category.Order;
 }
        public ActionResult Create()
        {
            var CategoryEdit = new CategoryEdit
            {
            };

            return(View(CategoryEdit));
        }
Exemple #9
0
 public bool UpdateCategory(CategoryEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity = ctx.Categories.Single(e => e.CategoryId == model.CategoryId);
         entity.CategoryName = model.CategoryName;
         return(ctx.SaveChanges() == 1);
     }
 }
Exemple #10
0
        public void UpdateCategory(CategoryEdit model)
        {
            var categoryToUpdate = _ctx.Categories.Find(model.CategoryId);

            if (categoryToUpdate != null)
            {
                categoryToUpdate.CategoryName = model.CategoryName;
                _ctx.SaveChanges();
            }
        }
Exemple #11
0
        public bool UpdateCategory(int id, CategoryEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Categories.SingleOrDefault(e => e.CategoryId == id);
                entity.Name = model.Name;

                return ctx.SaveChanges() == 1;
            }
        }
        public bool UpdateCategory(CategoryEdit model)
        {
            Category editCategroy = _db.Categories.Single(c => c.CategoryId == model.CategoryId);

            editCategroy.CategoryId  = model.CategoryId;
            editCategroy.Title       = model.Title;
            editCategroy.Description = model.Description;

            return(_db.SaveChanges() > 0);
        }
 public IHttpActionResult Put(CategoryEdit model)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     _categoryService = new CategoryService();
     _categoryService.UpdateCategory(model);
     return(Ok());
 }
 public void EditCategoryApplication()
 {
     CategoryEdit.ClickOn();
     CategoryName.Clear();
     CategoryApprove.ClickOn();
     softAssert.VerifyElementIsPresent(CategoryNameValidation);
     CategoryName.EnterClearText(Constant.CategoryName + RandomNumber.smallNumber());
     CategoryApprove.ClickOn();
     softAssert.VerifySuccessMsg();
 }
Exemple #15
0
        public bool UpdateCategory(CategoryEdit model)
        {
            var entity = _context
                         .Categories
                         .Single(e => e.Id == model.Id && e.AuthorId == _authorId);

            entity.Name = model.Name;

            return(_context.SaveChanges() == 1);
        }
        //Get: Category/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service  = new CategoryService();
            var detail   = service.GetCategory(id);
            var category = new CategoryEdit()
            {
                CategoryName = detail.CategoryName
            };

            return(View(category));
        }
        public ActionResult Edit(int id)
        {
            var service = CreateCategoryService();
            var detail  = service.GetCategoryById(id);
            var model   =
                new CategoryEdit
            {
                Name = detail.Name
            };

            return(View(model));
        }
Exemple #18
0
        //Добавить катеогрию

        private void addCategory_Click(object sender, RoutedEventArgs e)
        {
            CategoryModel m = new CategoryModel();

            m.ParentName = (tree.SelectedItem as CategoryModel).Name;
            CategoryEdit edt = new CategoryEdit(m);

            //  string sql="select "
            edt.ShowDialog();
            // ProductEdit edtp = new ProductEdit();
            // edtp.ShowDialog();
        }
Exemple #19
0
        //Get category edit
        public ActionResult EditCategory(int id)
        {
            var service = new CategoryService();
            var detail  = service.GetCategoryById(id);
            var model   = new CategoryEdit
            {
                CategoryId   = detail.CategoryId,
                CategoryName = detail.CategoryName
            };

            return(View(model));
        }
Exemple #20
0
        public ActionResult Edit(int id)
        {
            var detail = _service.GetCategoryById(id);
            var model  =
                new CategoryEdit
            {
                CatID   = detail.CatID,
                CatName = detail.CatName
            };

            return(View(model));
        }
        public bool UpdateCategory(CategoryEdit model)
        {
            using (var top = new ApplicationDbContext())
            {
                var topic =
                    top
                    .Categories
                    .Single(e => e.CategoryId == model.CategoryId);     //&& e.OwnerId == _userId);
                topic.CategoryTitle = model.CategoryTitle;

                return(top.SaveChanges() == 1);
            }
        }
Exemple #22
0
        public static Category MapToCategory(this CategoryEdit category)
        {
            if (category is null)
            {
                return(null);
            }

            return(new()
            {
                Id = category.Id,
                Name = category.Name
            });
        }
Exemple #23
0
        // GET: Category/Edit/{id}
        public ActionResult Edit(int id)
        {
            var detail = service.GetCategoryById(id);

            var model = new CategoryEdit()
            {
                CategoryId   = detail.CategoryId,
                CategoryName = detail.CategoryName,
                CategoryType = detail.CategoryType
            };

            return(View(model));
        }
Exemple #24
0
        public ActionResult Edit(int id)
        {
            var service = CreateCategoryService();
            var detail  = service.GetCategorybyId(id);
            var model   = new CategoryEdit
            {
                CategoryId   = detail.CategoryId,
                CategoryName = detail.CategoryName,
                CategoryDesc = detail.CategoryDesc
            };

            return(View(model));
        }
Exemple #25
0
        //GET: Category/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = new CategoryService();
            var update  = service.GetCategoryById(id);

            var model = new CategoryEdit
            {
                CategoryId   = update.CategoryId,
                CategoryName = update.CategoryName
            };

            return(View(model));
        }
        public IHttpActionResult Put(CategoryEdit model)
        {
            var newCat = svc.UpdateCategory(model);

            if (newCat == false)
            {
                return(BadRequest());
            }
            else
            {
                return(Ok());
            }
        }
Exemple #27
0
        //Get: Edit
        public ActionResult Edit(int id)
        {
            var service = new CategoryService();
            var detail  = service.GetCategoryById(id);
            var model   = new CategoryEdit
            {
                CategoryId  = detail.CategoryId,
                Name        = detail.Name,
                Description = detail.Description
            };

            return(View(model));
        }
Exemple #28
0
        public ActionResult Edit(int id)
        {
            var service = CreateCategoryService();
            var detail  = service.GetCategoryByID(id);
            var model   =
                new CategoryEdit
            {
                CategoryID    = detail.CategoryID,
                CategoryTitle = detail.CategoryTitle,
            };

            return(View(model));
        }
 public IHttpActionResult Put(CategoryEdit category)
 {
     if (ModelState.IsValid)
     {
         var service = CreateCategoryService();
         if (!service.UpdateCategory(category))
         {
             return(InternalServerError());
         }
         return(Ok());
     }
     return(BadRequest(ModelState));
 }
        public bool UpdateCategory(CategoryEdit model) // Updates the category
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Categories
                             .Single(e => e.CategoryID == model.CategoryID && e.AccountID == _userID);

                entity.CategoryID   = model.CategoryID;
                entity.CategoryType = model.CategoryType;

                return(ctx.SaveChanges() == 1);
            }
        }