public PriceCostDto UpdatePriceCost(MonthReportDto monthReport, int year, int month) { var newPriceCost = new PriceCost() { Type = monthReport.Type, Procedure = monthReport.Procedure, DateEnd = new DateTime(year, month, 1).AddMonths(1).AddDays(-1), Value = monthReport.CostPrice, }; var dbPriceCost = _priceCostDao.Get( x => x.Procedure == newPriceCost.Procedure && x.Type == newPriceCost.Type && x.DateEnd == newPriceCost.DateEnd); if (dbPriceCost.Any()) { if (dbPriceCost.Count == 1) { var dbPriceCostOld = dbPriceCost.First(); dbPriceCostOld.Value = newPriceCost.Value; _priceCostDao.Update(dbPriceCostOld); return(_map(dbPriceCostOld)); } else { throw new Exception("Найдено больше одной себестоимости!"); } } else { _priceCostDao.Create(newPriceCost); return(_map(newPriceCost)); } }
public PriceCostDto Add(PriceCostDto dto) { var item = new PriceCost() { Procedure = dto.Procedure, Type = dto.Type, Value = dto.Value, DateEnd = dto.DateEnd, }; _dao.Create(item); return(_map(item)); }
private PriceCostDto _map(PriceCost dbPriceCostOld) { return(new PriceCostDto(dbPriceCostOld)); }