예제 #1
0
        public override void Execute()
        {
            if (Product is Product)
            {
                Product prod = (Product as Product);
                prod.GetStorageStatus();
                if (prod.StorageWithAmount == null)
                {
                    throw new Exception("FAIL!");
                }
                if (!prod.StorageWithAmount.ContainsKey(shopID))
                {
                    prod.StorageWithAmount.TryAdd(shopID, -Amount);
                }
                else
                {
                    prod.StorageWithAmount[shopID] -= Amount;
                }
                UpdateProductEvent?.Invoke(prod);
                if (!HideMessageBox && prod.StorageWithAmount.Where(x => x.Value < 0).Count() > 0)
                {
                    // Hvis det er nogle storageroom med negativ værdi
                    StringBuilder Text = new StringBuilder();

                    Text.Append("Produktet: " + prod.Name + "'s lagerstatus har fejl!\n");

                    foreach (KeyValuePair <int, int> strorageWithAmount in prod.StorageWithAmount)
                    {
                        string AppendString = "";
                        if (strorageWithAmount.Value < 0 && _storageController.StorageRoomDictionary.ContainsKey(strorageWithAmount.Key))
                        {
                            AppendString = " **** - " + _storageController.StorageRoomDictionary[strorageWithAmount.Key].Name + " har " + strorageWithAmount.Value.ToString() + " stk\n";
                        }
                        else
                        {
                            if (_storageController.StorageRoomDictionary.ContainsKey(strorageWithAmount.Key))
                            {
                                AppendString = " - " + _storageController.StorageRoomDictionary[strorageWithAmount.Key].Name + " har " + strorageWithAmount.Value.ToString() + " stk\n";
                            }
                        }
                        Text.Append(AppendString);
                    }
                    string Output = Text.ToString();
                    var    NewBox = MessageBox.Show(Text.ToString());
                }
                prod.UpdateInDatabase();
            }
            else if (Product is TempProduct)
            {
                Product.ID = TempProduct.GetNextID();
                Product.UploadToDatabase();
                _storageController.TempProductDictionary.TryAdd(Product.ID, Product as TempProduct);
            }
        }
        public ActionResult Edit(ProductUpdateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var @event = new UpdateProductEvent(model.Id);

                if (!string.Equals(model.Name, model.Original.Name))
                {
                    @event.Name = model.Name;
                }
                if (!string.Equals(model.Description, model.Original.Description))
                {
                    @event.Description = model.Description;
                }
                if (!string.Equals(model.Color, model.Original.Color))
                {
                    @event.Color = model.Color;
                }
                if (!string.Equals(model.Size, model.Original.Size))
                {
                    @event.Size = model.Size;
                }
                if (!decimal.Equals(model.Price, model.Original.Price))
                {
                    @event.Price = model.Price;
                }

                var addedTags   = model.TagsList?.Where(x => model.Original.Tags?.Contains(x) != true);
                var removedTags = model.Original.Tags?.Where(x => model.TagsList?.Contains(x) != true);

                if (addedTags?.Any() == true)
                {
                    @event.AddedTags = addedTags;
                }
                if (removedTags?.Any() == true)
                {
                    @event.RemovedTags = removedTags;
                }

                var result = _service.Update(@event);

                PopulateModelState(result);

                if (ModelState.IsValid)
                {
                    return(RedirectToAction("Index", "Product"));
                }
            }

            return(View(model));
        }
예제 #3
0
 public EventResult Update(UpdateProductEvent @event)
 {
     return(_factory.GetHandler <UpdateProductEvent>().Apply(@event, new EventOptions {
         Store = true
     }));
 }
예제 #4
0
 public Task HandleAsync(UpdateProductEvent instance)
 {
     return(this.RebuildIndexAsync());
 }
예제 #5
0
 public void HandleOnUpdateProductEvent(UpdateProductEvent ev)
 {
     var product = ProductsRepository.Get(ev.Id);
     Console.WriteLine("EventsHandlers: HandleUpdateProductEvent");
 }
예제 #6
0
 public Task Handle(UpdateProductEvent notification, CancellationToken cancellationToken) => Task.CompletedTask;