public ActionResult Create(PurchaseViewModel model) { try { if (!ModelState.IsValid) { return(View(model)); } var purchase = _mapper.Map <Purchase>(model); purchase.PurchaseDate = DateTime.Now; // To inject you own date picker var IsSuccess = _repo.Create(purchase); if (!IsSuccess) { ModelState.AddModelError("", "Sorry, Something went wrong..."); return(View(model)); } return(RedirectToAction(nameof(Index))); } catch { ModelState.AddModelError("", "Sorry, Something went wrong..."); return(View()); } }
public IActionResult Create(PurchaseCreateVM purchase, IFormCollection form) { if (ModelState.IsValid) { Purchase newPurchase = _mapper.Map <Purchase>(purchase); newPurchase.Masks = new List <PurchasedMasks>(); var data = form["selectedMasks"]; var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(data); foreach (var key in values.Keys) { if (key.Equals(String.Empty)) { continue; } Mask mask = _mrepo.FindByFabricId(key); _mrepo.Save(); int quantity = Int32.Parse(values[key]); newPurchase.Masks.Add(new PurchasedMasks { Mask = mask, Quantity = quantity, Purchase = newPurchase }); } _prepo.Create(newPurchase); } //return RedirectToAction(nameof(Index)); return(RedirectToAction(nameof(Create))); }
public void Purchase(PurchaseModel entity) { var purchase = _mapper.Map <Purchase>(entity); purchase.CustomerId = entity.CustomerId; purchase.ArchivePath = entity.ArchivePath; _purchaseRepository.Create(purchase); }
public ActionResult Create([Bind(Include = "Id,Phone,Date,BrandId,CarModelId,ConfigId,CarColorId,FirstName,LastName,Email")] Purchase purchase) { if (ModelState.IsValid) { var pur = _service.Create(); pur.Phone = purchase.Phone; pur.FirstName = purchase.FirstName; pur.LastName = purchase.LastName; pur.Email = purchase.Email; repo.Create(pur); return(RedirectToAction("PurchaseConfirm", new { pur.Id })); } return(View(_service.Create())); }
private static void displayAddNewPurchase(ICustomerRepository customerRepository, IPurchaseRepository purchaseRepository, ICustomerContext customerContext) { Console.Clear(); Console.WriteLine("\n................. ADD A NEW PURCHASE RECORD ....................\n"); Console.WriteLine("\n\nCurrent Customer's on Record for reference as needed:\n"); displayCustomerGraph(customerRepository); var customer = collectCustomerFromUser(customerRepository); if (customer == null) { displayMenu(); return; } double?subtotal = collectSubTotalFromUser(); if (!subtotal.HasValue) { displayMenu(); return; } State purchaseState = collectPurchaseStateFromUser(stateRepository); if (purchaseState == null) { displayMenu(); return; } try { var purchase = purchaseRepository.Create(customer.Id, subtotal.Value, purchaseState); customerContext.MakePurchase(purchase); Console.WriteLine("Purchase Successfully Recorded.\n"); Console.WriteLine("\n\nPress Enter to return to the menu"); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { displayMenu(); } return; }
/// <summary> /// Check all lots for sale at the end of the trading period and sends a letter to the seller and the customer /// </summary> public void CheckAllLotEntities() { lock (padlock) { IEnumerable <LotEntity> lots = GetAllForSaleLotEntities().Where(lot => DateTime.Now >= (lot.StartDate + new TimeSpan(lot.Duration, 0, 0, 0))); if (lots != null) { bool isEntryChanges = false; foreach (var lot in lots) { if (lot.LastPrice != null) { lot.State = LotStateEntity.Sold; string sellerMailSubject = "Your lot is sold"; string sellerMailBody = string.Format("Your lot {0} is sold for the {1} byn. Please come to the auction office for the completion of the sale transaction.", lot.Name, lot.LastPrice); UserEntity seller = lot.User; seller.SendMessage(sellerMailSubject, sellerMailBody); string customerMailSubject = "You won the auction"; string customerMailBody = string.Format("You won lot {0} for the {1} byn. Please come to the auction office for the completion of the sale transaction.", lot.Name, lot.LastPrice); UserEntity customer = GetMaxBidOwner(lot); PurchaseEntity purchase = new PurchaseEntity { Lot = lot, LotId = lot.Id, User = customer, UserId = customer.Id, Date = DateTime.Now }; purchaseRepository.Create(purchase.ToDalPurchase()); customer.SendMessage(customerMailSubject, customerMailBody); } else { lot.State = LotStateEntity.Unsold; string sellerMailSubject = "Your lot not sold"; string sellerMailBody = string.Format("Your lot {0} with the start price {1} byn not sold.", lot.Name, lot.StartPrice); UserEntity seller = lot.User; seller.SendMessage(sellerMailSubject, sellerMailBody); } lotRepository.Update(lot.ToDalLot()); isEntryChanges = true; } if (isEntryChanges) { uow.Commit(); } } } }
public async Task <PurchaseIdDto> Purchase([FromBody] PurchaseRequestDto req) { var prizeId = req.PrizeId; var userEmail = User.FindFirst(ClaimTypes.Email).Value; var prize = await _prizeManager.GetPrizeById(prizeId); var canBuy = await _purchaseLogic.CheckIfUserCanBuy(userEmail, prizeId); if (!canBuy) { throw new Exception(); //Don't know what kind of specific exception should be here } var id = _purchaseRepository.Create(userEmail, prizeId, prize.Price); return(new PurchaseIdDto { Id = id }); }
public void Create(string photoPath, int inquiryId, int vkId) { _purchaseRepository.Create(photoPath, inquiryId, vkId); }
public ActionResult <Purchase> PostPurchase(List <PurchaseDTO> purchaseDetail) { if (!ModelState.IsValid && purchaseDetail != null && purchaseDetail.Count > 0) { return(BadRequest(new { Message = "Required data missing" })); } //Check available quantity foreach (var item in purchaseDetail) { //Valid if (item.ProductQuantity <= 0) { return(BadRequest(new { Message = string.Concat("ProductId <", item.ProductId, "> quantity must be greater than 0") })); } if (!_productRepository.CheckQuantityAvailable(item.ProductId, item.ProductQuantity)) { return(BadRequest(new { Message = string.Concat("ProductId <", item.ProductId, "> unavailable or insufficient stock") })); } } var userId = int.Parse(User.Identity.Name); var clientId = purchaseDetail.First().ClientId ?? userId; var newPurchase = new Purchase(); newPurchase.ClientId = clientId; newPurchase.NumberOfProducts = purchaseDetail.Count(); newPurchase.Total = 0; //Zero by default newPurchase.CreatedAt = DateTime.Now; newPurchase.CreatedBy = userId; _purchaseRepository.Create(newPurchase); foreach (var item in purchaseDetail) { var product = _productRepository.GetById(item.ProductId); //Create purchase detail var newPurchaseProduct = new PurchaseProducts(); newPurchaseProduct.PurchaseId = newPurchase.Id; newPurchaseProduct.ProductId = product.Id; newPurchaseProduct.ProductQuantity = item.ProductQuantity; newPurchaseProduct.Price = (decimal)product.Price; newPurchaseProduct.SubTotal = decimal.Round((newPurchaseProduct.ProductQuantity * newPurchaseProduct.Price), 2); newPurchaseProduct.CreatedBy = userId; newPurchaseProduct.CreatedAt = DateTime.Now; _purchaseProductRepository.Create(newPurchaseProduct); //Update total purchase newPurchase.Total += newPurchaseProduct.SubTotal; //Decrement product stock product.Stock -= newPurchaseProduct.ProductQuantity; product.UpdatedAt = DateTime.Now; product.UpdatedBy = userId; _productRepository.Update(product); } //Update total purchase newPurchase.UpdatedAt = DateTime.Now; newPurchase.UpdatedBy = userId; _purchaseRepository.Update(newPurchase); return(CreatedAtAction("GetPurchase", new { id = newPurchase.Id }, newPurchase)); }
public void CreatePurchase(PurchaseEntity purchase) { purchaseRepository.Create(purchase.ToDalPurchase()); uow.Commit(); }
public bool CreatePurchase(string fromCurrencyId, string toCurrencyId, DateTime when, decimal price, double quantity, string exchangeId, string userId) { var result = false; if (!string.IsNullOrEmpty(fromCurrencyId) && !string.IsNullOrEmpty(toCurrencyId)) { var mergedList = GetMergedCurrencyList(); var fromCurrency = _mergedCurrencyList.FirstOrDefault(x => x.Id == fromCurrencyId); var toCurrency = _mergedCurrencyList.FirstOrDefault(x => x.Id == toCurrencyId); // make sure that the currency being bought is a crypto // no sence in having a USD -> EUR purchase // or keeping a fiat currency in portfolio if (fromCurrency != null && (toCurrency != null && toCurrency.IsCryptoCurrency)) { // purchase date at least greater than 05-2013 if (when > new DateTime(2013, 5, 1)) { // price and qty at least bigger than default values if (price > default(decimal) && quantity > default(double)) { var purchase = new Purchase { FromCurrency = fromCurrency, ToCurrency = toCurrency as CryptoCurrency, Price = price, Quantity = quantity, TimeStampUTC = when.ToUniversalTime(), Exchange = new Exchange { Name = exchangeId }, User = new User { Email = userId } }; var fiatCurrencies = mergedList.Where(x => x.IsFiatCurrency) .Select(x => x as FiatCurrency).ToList(); if (fromCurrency.IsFiatCurrency) { // if the buying currency was already a fiat, then add it to the price estimations list // more frequent scenario is trading from crypto to crypto fiatCurrencies.RemoveAll(x => x.Id == fromCurrency.Id); purchase.PriceEstimations.Add(fromCurrency.Id, price); } var estimatePrices = GetHistoricalPriceEstimations(toCurrency.Id, fiatCurrencies, when); foreach (var estimate in estimatePrices) { var fiat = fiatCurrencies.FirstOrDefault(x => x.Id == estimate.ToCurrencyId); if (fiat != null) { purchase.PriceEstimations.Add(fiat.Id, estimate.Price); } } var key = _purchaseRepository.Create(purchase); result = key != null; } } } } return(result); }