public static PartAddInputDtoModel Map(PartAddInputModel model) { var partDto = new PartAddInputDtoModel { PartId = model.PartId, Price = model.Price, Quantity = model.Quantity, }; return(partDto); }
public async Task AddQuantityAsync(PartAddInputDtoModel model) { var part = await this.parts.All().FirstOrDefaultAsync(x => x.Id == model.PartId); var totalQuantity = part.Quantity + model.Quantity; if (part.InComePrice != model.Price) { var averagePrice = Math.Round(((part.Quantity * part.InComePrice) + (model.Quantity * model.Price)) / totalQuantity, 2); part.InComePrice = averagePrice; } part.Quantity = totalQuantity; this.parts.Update(part); await this.parts.SaveChangesAsync(); }