public Result UpdateItem(ItemData item) { var currency = _languageAndCurrencyAccessor.GetCurrencyByCode(item.SelectedItemCurrency).Payload; var donateItem = new DonateItem { ItemID = item.ItemID, ItemType = item.SelectedItemType, Need = item.SelectedItemType == "direct" ? Math.Min(item.CurrentAmount.Value / item.GoalAmount.Value, 1) : item.Need.Value, Price = item.Price, CurrencyID = currency.CurrencyID }; _donateAccessor.UpdateDonateItem(donateItem); _donateAccessor.UpdateItemTitle(item.ItemID, 1, item.EnglishName); _donateAccessor.UpdateItemTitle(item.ItemID, 2, item.SwahiliName); _donateAccessor.UpdateItemDescription(item.ItemID, 1, item.EnglishDescription); _donateAccessor.UpdateItemDescription(item.ItemID, 2, item.SwahiliDescription); if (item.SelectedItemType == "direct") { _inventoryAccessor.UpdateInventoryItem(donateItem.ItemID, item.CurrentAmount.Value, item.GoalAmount.Value, item.AutoDecrement, item.DecrementPerDay.Value); } else { _donateAccessor.UpdateCampaignItem(item.ItemID, (int)Math.Ceiling(item.Price), item.CurrentAmount.Value, currency.CurrencyID); } //var imageBase = request.ImageBase.Substring(request.ImageBase.IndexOf("base64,") + "base64,".Length); //var imageBytes = Convert.FromBase64String(imageBase); ////Add image here...maybe //using (var stream = new MemoryStream()) //{ // using (Image<Rgba32> image = Image.Load(imageBytes)) // { // var width = Math.Min(image.Width, image.Height); // image.Mutate(x => x.Crop(width, width)); // image.SaveAsJpeg(stream); // } // var bytes = stream.ToArray(); // var itemImage = new DonateItemImage // { // ItemImageID = 0, // ItemID = donateItem.ItemID, // ImageData = bytes // }; // _donateAccessor.AddImage(itemImage); //} return(new Result(true)); }
public bool EditInventoryItem(InventoryItem oldItem, InventoryItem newItem) { bool oneItemUpdated = false; try { oneItemUpdated = (1 == _inventoryAccessor.UpdateInventoryItem(oldItem, newItem)); } catch (Exception ex) { throw new ApplicationException("Inventory Update Failed", ex); } return(oneItemUpdated); }
public Result UpdateReadyItems() { try { var list = _donateAccessor.GetDonationsByStatus("Delivered"); list = list.Concat(_donateAccessor.GetDonationsByStatus("Purchased")).ToList(); var donateItems = _donateAccessor.GetDonateItems().Payload; foreach (var donationItem in list) { var donateItem = donateItems.First(x => x.ItemID == donationItem.ItemID); if (donationItem.NumberOfItems == null) { var campaignItem = _donateAccessor.GetCampaignItem(donateItem.ItemID).Payload; campaignItem.ActualAmount += donationItem.TotalAmount; _donateAccessor.UpdateCampaignItem(donateItem.ItemID, campaignItem.GoalAmount, campaignItem.ActualAmount, campaignItem.CurrencyID); } else { var inventoryItem = _inventoryAccessor.GetItem(donationItem.ItemID).Payload; inventoryItem.ActualAmount += donationItem.NumberOfItems.Value; _inventoryAccessor.UpdateInventoryItem(inventoryItem); donateItem.Need = Math.Min(Math.Ceiling(inventoryItem.ActualAmount) / inventoryItem.GoalAmount, 1); } _donateAccessor.UpdateDonateItem(donateItem); } if (list.Count > 0) { var donation = _donateAccessor.GetDonation(list[0].DonationID); donation.StatusID = 3; _donateAccessor.UpdateDonation(donation); } return(new Result(true)); } catch (Exception ex) { return(new Result(false, ex.Message)); } }