Esempio n. 1
0
        public void Handle(DeleteCategory message)
        {
            _log.Info("Delete: start to handle [{0}]", message.GetType().Name);

            // TODO: will refactor later
            _mongoClient = new MongoClient(new MongoUrl("mongodb://127.0.0.1:27017"));
            var db = _mongoClient.GetDatabase("magazine");

            if (db == null)
            {
                db = _mongoClient.GetDatabase("magazine");
            }

            var col = db.GetCollection <CategoryViewResponse>("categories");

            if (col == null)
            {
                db.CreateCollection("categories");
                col = db.GetCollection <CategoryViewResponse>("categories");
            }

            var filter = Builders <CategoryViewResponse> .Filter.Eq("_id", message.Key);

            var result = col.DeleteOne(filter);
        }
Esempio n. 2
0
 public void DeleteFormsCategoryApplication()
 {
     DeleteCategory.ClickOn();
     PopupApprove.ClickWait();
     softAssert.VerifyElementHasEqualInsideWindow(utility.TableCount(formsCategoryTableCount), Constant.tmpTableCount, Pages.Home_Page.PopupCloseClass);
     Pages.Home_Page.PopupCloseClass.ClickOn();
 }
        public void Should_delete_category()
        {
            // Arrange
            var command = new DeleteCategory
            {
                Id = 1
            };

            var entity = new Category {
                Id = 1, Name = "test category"
            };

            var fakeRepo = new Mock <ICategoryRepository>();

            fakeRepo.Setup(m => m.Delete(It.IsAny <Category>())).Returns(1);
            fakeRepo.Setup(m => m.Find(entity.Id)).Returns(entity);

            // Act
            var res = Task.Run(() => new DeleteCategoryHandler(fakeRepo.Object, _mapper).Handle(command, default)).Result;

            // Assert
            fakeRepo.Verify(x => x.Delete(It.IsAny <Category>()), Times.Once());
            fakeRepo.Verify(x => x.Find(entity.Id), Times.Once());
            Assert.Equal(entity, res);
        }
Esempio n. 4
0
 private void deleteBtn_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(ctgry_Id) || string.IsNullOrEmpty(ctgry_Txt.Text))
     {
         MessageBox.Show("Oops Category is not selected !! Click on Category");
     }
     else
     {
         DialogResult dialogResult = MessageBox.Show("Are You Sure To Delete ", "Deleting Category", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             DeleteCategory deleteCategory = new DeleteCategory();
             if (deleteCategory.deleteCategory(ctgry_Id))
             {
                 MessageBox.Show("Category " + ctgry_Txt.Text + " is Deleted from Database");
                 cnt = 0;
                 fillData.fillDataGridView(this.dataGridView1);
                 ctgry_Txt.Text = "";
             }
             else
             {
                 MessageBox.Show("Error!! Category:" + ctgry_Txt.Text + " is not Deleted from Database");
             }
         }
     }
 }
Esempio n. 5
0
        public IActionResult Delete(string name)
        {
            var q = new DeleteCategory(_configuration);

            q.RemoveCategory(name);
            return(RedirectToAction("ShowCategories"));
        }
Esempio n. 6
0
        public async Task <IActionResult> Delete(Guid id, DeleteCategory command)
        {
            command.Id = id;

            await Dispatcher.SendAsync(command);

            return(NoContent());
        }
        public async Task <Unit> Handle(DeleteCategory message, CancellationToken cancellationToken)
        {
            var categoryToDelete = await context.Categories.FirstAsync(c => c.Id == message.Id);

            context.Categories.Remove(categoryToDelete);
            await context.SaveChangesAsync();

            return(Unit.Value);
        }
Esempio n. 8
0
        public async Task DeleteAsync(DeleteCategory command)
        {
            var category = await _dbContext.Categories
                           .Include(x => x.Forums)
                           .FirstOrDefaultAsync(x =>
                                                x.SiteId == command.SiteId &&
                                                x.Id == command.Id &&
                                                x.Status != StatusType.Deleted);

            if (category == null)
            {
                throw new DataException($"Category with Id {command.Id} not found.");
            }

            category.Delete();
            _dbContext.Events.Add(new Event(command.SiteId,
                                            command.UserId,
                                            EventType.Deleted,
                                            typeof(Category),
                                            category.Id));

            var otherCategories = await _dbContext.Categories
                                  .Where(x =>
                                         x.SiteId == command.SiteId &&
                                         x.Id != command.Id &&
                                         x.Status != StatusType.Deleted)
                                  .ToListAsync();

            for (int i = 0; i < otherCategories.Count; i++)
            {
                otherCategories[i].Reorder(i + 1);
                _dbContext.Events.Add(new Event(command.SiteId,
                                                command.UserId,
                                                EventType.Reordered,
                                                typeof(Category),
                                                otherCategories[i].Id,
                                                new
                {
                    otherCategories[i].SortOrder
                }));
            }

            foreach (var forum in category.Forums)
            {
                forum.Delete();
                _dbContext.Events.Add(new Event(command.SiteId,
                                                command.UserId,
                                                EventType.Deleted,
                                                typeof(Forum),
                                                forum.Id));
            }

            await _dbContext.SaveChangesAsync();

            _cacheManager.Remove(CacheKeys.Categories(command.SiteId));
            _cacheManager.Remove(CacheKeys.CurrentForums(command.SiteId));
        }
 private void buttonSelectDelete_Click(object sender, EventArgs e)
 {
     if (isCategorySelected)
     {
         DeleteCategory deleteCategory = new DeleteCategory();
         deleteCategory.Show();
     }
     else
     {
         DeleteProduct deleteProduct = new DeleteProduct();
         deleteProduct.Show();
     }
 }
Esempio n. 10
0
        public object Post(DeleteCategory request)
        {
            var result = icategoryService.DeleteCategory(request.Id);

            if (result.Success)
            {
                return(null);
            }

            // STATUS CODE

            return(null);
        }
Esempio n. 11
0
        public void HandleAsync_ShouldInvokeSpecificMethods()
        {
            var command = new DeleteCategory
            {
                ResourceId = Guid.NewGuid(),
            };

            _handler.Invoking(async x => await x.HandleAsync(command))
            .Should()
            .NotThrow();

            _categoryService.Verify(x => x.DeleteAsync(command.ResourceId), Times.Once);
            _eventPublisher.Verify(x => x.PublishAsync(It.IsAny <CategoryDeleted>()), Times.Once);
        }
        public async Task Delete()
        {
            var handler = new CategoryHandler(BasicNeeds);

            var categ = context.Categories.First();
            var query = new DeleteCategory
            {
                Id = categ.Id,
            };

            await handler.Handle(query, CancellationToken.None);

            var cat = await context.Categories.AnyAsync <CategoryDb>(p => p.Id == categ.Id);

            Assert.IsFalse(cat);
        }
Esempio n. 13
0
        public async Task <ActionResult> Delete(Guid id)
        {
            var site = await _contextService.CurrentSiteAsync();

            var user = await _contextService.CurrentUserAsync();

            var command = new DeleteCategory
            {
                Id     = id,
                SiteId = site.Id,
                UserId = user.Id
            };

            await _categoryService.DeleteAsync(command);

            return(Ok());
        }
Esempio n. 14
0
        public IApiResult Delete(DeleteCategory operation)
        {
            var result = operation.ExecuteAsync().Result;

            if (result is ValidationsOutput)
            {
                return(new ApiResult <List <ValidationItem> >()
                {
                    Data = ((ValidationsOutput)result).Errors
                });
            }
            else
            {
                return(new ApiResult <object>()
                {
                    Status = ApiResult <object> .ApiStatus.Success
                });
            }
        }
Esempio n. 15
0
        public static ResultState DeleteCategory(this DiscourseApi api, int categoryId, string username = DefaultUsername)
        {
            var route = String.Format("/c/{0}", categoryId);
            var data  = new DeleteCategory(categoryId);

            var result = api.ExecuteRequest <RestResponse>(route, Method.DELETE, true, username, null, data);

            switch (result.StatusCode)
            {
            case (HttpStatusCode)422:
                return(ResultState.Unchanged);

            case HttpStatusCode.Accepted:
                return(ResultState.Modified);

            default:
                return(ResultState.Error);
            }
        }
Esempio n. 16
0
        private void deleteBtn_Click(object sender, EventArgs e)
        {
            if (ctgry_Id != "")
            {
                DeleteCategory deleteCategory = new DeleteCategory();
                if (deleteCategory.deleteCategory(ctgry_Id))
                {
                    ctgry_Txt.Text = "";
                    MessageBox.Show("Category " + ctgry_Txt.Text + " is Deleted from Database");
                    cnt = 0;

                    fillData.fillDataGridView(this.dataGridView1);
                }
                else
                {
                    MessageBox.Show("Error!! Category:" + ctgry_Txt.Text + " is not Deleted from Database");
                }
            }
        }
        public ActionResult DeleteConfirm(int id)
        {
            DeleteCategory ViewModel = new DeleteCategory();

            string url = "CategoryData/FindCategory/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                CategoryDto category = response.Content.ReadAsAsync <CategoryDto>().Result;
                ViewModel.category = category;

                url      = "FaqData/GetFaqsByCategoryId/" + category.CategoryID;
                response = client.GetAsync(url).Result;
                IEnumerable <FaqDto> faqList = response.Content.ReadAsAsync <IEnumerable <FaqDto> >().Result;
                ViewModel.faqList = faqList;

                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
Esempio n. 18
0
 private void BtnDelete_Click(object sender, EventArgs e)
 {
     DeleteCategory?.Invoke(sender, e);
 }
 public async Task<StatusData<string>> DeleteCategory(DeleteCategory request, SystemSession session)
 {
     return (await Task.Factory.StartNew(() => Client.UserService.deleteMultipleCategories(request.UserId, request.CategoryList, session.GetSession())).ConfigureAwait(false)).GetStatusData<string>();
 }
 public Task<StatusData<string>> DeleteCategory(DeleteCategory request, SystemDbStatus mode, SystemSession session)
 {
     return _jUnitOfWork.Category.DeleteCategory(request, session);
 }
        public async Task <IActionResult> Delete(DeleteCategory category)
        {
            await mediator.Send(category);

            return(Ok());
        }
Esempio n. 22
0
      public static void Main(string[] args)
      {
          logger.Info("Program started");
          try
          {
              string choice;
              do
              {
                  Menu menu = new Menu();
                  menu.MenuClass();

                  Console.WriteLine("\"q\" to quit");
                  choice = Console.ReadLine();
                  Console.Clear();
                  logger.Info($"Option {choice} selected");


                  // 1. DISPLAY CATEGORIES
                  if (choice == "1")
                  {
                      DisplayCategories dc = new DisplayCategories();
                      dc.DisplayAllCategories();
                  }

                  // 2. ADD CATEGORY
                  else if (choice == "2")
                  {
                      AddCategory ac = new AddCategory();
                      ac.AddCategoryClass();
                  }

                  // 3. DISPLAY CATEGORY AND RELATED PRODUCTS
                  else if (choice == "3")
                  {
                      DisplayCatRelatedProd dc = new DisplayCatRelatedProd();
                      dc.DisplayCatRelatedProdClass();
                  }

                  // 4. DISPLAY ALL CATEGORIES AND THEIR RELATED PRODUCTS
                  else if (choice == "4")
                  {
                      DisplayAllCatRelatedProd dac = new DisplayAllCatRelatedProd();
                      dac.DisplayAllCatRelatedProdClass();
                  }

                  // 5. EDIT CATEGORY NAME
                  else if (choice == "5")
                  {
                      EditCatName ecn = new EditCatName();
                      ecn.EditCatNameClass();
                  }

                  // 6. DELETE CATEGORY
                  else if (choice == "6")
                  {
                      DeleteCategory dc = new DeleteCategory();
                      dc.DeleteCategoryClass();
                  }

                  // 7. DISPLAY PRODUCTS
                  else if (choice == "7")
                  {
                      DisplayProducts dp = new DisplayProducts();
                      dp.DisplayProductsClass();
                  }

                  // 8. ADD PRODUCT
                  else if (choice == "8")
                  {
                      AddProduct ap = new AddProduct();
                      ap.AddProductClass();
                  }

                  // 9. DISPLAY A SPECIFIC PRODUCT
                  else if (choice == "9")
                  {
                      DisplaySpecificProduct dsp = new DisplaySpecificProduct();
                      dsp.DisplaySpecificProductClass();
                  }

                  // 10. EDIT PRODUCT
                  else if (choice == "10")
                  {
                      EditProduct ep = new EditProduct();
                      ep.EditProductClass();
                  }

                  // DELETE PRODUCT
                  else if (choice == "11")
                  {
                      DeleteProduct dp = new DeleteProduct();
                      dp.DeleteProductClass();
                  }

                  Console.WriteLine();
              } while (choice.ToLower() != "q");
          }
          catch (Exception ex)
          {
              logger.Error(ex.Message);
          }
          logger.Info("Program ended");
      }
Esempio n. 23
0
        public async Task <IActionResult> Delete([FromBody] DeleteCategory command)
        {
            await DispatchAsync(command);

            return(await Get());
        }
Esempio n. 24
0
        public IEnumerable Handle(DeleteCategory c)
        {
            var item = Mapper.DynamicMap <CategoryDeleted>(c);

            yield return(item);
        }
Esempio n. 25
0
 public async Task <Unit> DeleteCategoryAsync([FromBody] DeleteCategory deleteCategory)
 {
     return(await _mediator.Send(deleteCategory));
 }
        public async Task <HttpResponseMessage> Delete([FromBody] DeleteCategory request)
        {
            var response = await _service.DeleteCategory(request, SystemDbStatus.Deleted, Request.GetSession()).ConfigureAwait(false);

            return(Request.SystemResponse(response));
        }
 public async Task <StatusData <string> > DeleteCategory(DeleteCategory request, SystemSession session)
 {
     return((await Task.Factory.StartNew(() => Client.UserService.deleteMultipleCategories(request.UserId, request.CategoryList, session.GetSession())).ConfigureAwait(false)).GetStatusData <string>());
 }
Esempio n. 28
0
 public IActionResult DeleteCategory([FromServices] DeleteCategory deleteCategory, int id) =>
 Ok(deleteCategory.Do(id));
Esempio n. 29
0
 public async Task <IActionResult> DeleteCategory(
     Guid id,
     [FromServices] DeleteCategory deleteCategory) =>
 Ok((await deleteCategory.DoAsync(id)));
        public async Task <SystemDbStatus> DeleteCategory(DeleteCategory request, SystemDbStatus mode)
        {
            var categoryIdsObj = new ObjectParameter("USERCATEGORYTYPEIDS", string.Join(",", request.CategoryList));

            return((SystemDbStatus)await Task.Factory.StartNew(() => Context.PROC_UPSERT_CATEGORY(request.UserId, (byte?)mode, string.Empty, string.Empty, null, categoryIdsObj).FirstOrDefault().GetValueOrDefault()).ConfigureAwait(false));
        }
Esempio n. 31
0
 public void Handle(DeleteCategory message)
 {
     Events.Publish(new CategoryDeleted(message.AggregateId));
 }
Esempio n. 32
0
 public async Task <IActionResult> DeleteCategory(
     int id,
     [FromServices] DeleteCategory deleteCategory) =>
 Ok(await deleteCategory.Action(id));