Пример #1
0
        public async Task <IHttpActionResult> PutAlter(int id, AlterReport alterReport)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != alterReport.Id)
            {
                return(BadRequest());
            }

            db.Entry(alterReport).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AlterReportExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public bool QuickUpdate(DateTime date, string shopId)
        {
            BusinessDbContext db       = BusinessDbContext.Create();
            ReportDbContext   reportDb = new ReportDbContext();

            date = date.Date;

            var salesToday = db.Sales.Where(x => x.ShopId == shopId && DbFunctions.TruncateTime(x.Created) == date)
                             .ToList();

            var report = reportDb.SaleReports.Where(x => x.ShopId == shopId).FirstOrDefault(x => x.Date == date);

            if (report == null)
            {
                bool b = ShopStart(date, shopId);
            }

            List <SaleReport> allReports        = reportDb.SaleReports.Where(x => x.ShopId == shopId && DbFunctions.TruncateTime(x.Date) == date).ToList();
            SaleReport        reportSaleTypeAll = allReports.First(x => x.SaleType == SaleType.All);

            CalculateAmounts(reportSaleTypeAll, salesToday);
            reportSaleTypeAll.Modified = DateTime.Now;
            reportDb.Entry(reportSaleTypeAll).State = EntityState.Modified;
            SaleReport  reportDealerSale = allReports.First(x => x.SaleType == SaleType.DealerSale);
            List <Sale> dealerSalesToday = salesToday.Where(x => x.IsDealerSale).ToList();

            CalculateAmounts(reportDealerSale, dealerSalesToday);
            reportDealerSale.Modified = DateTime.Now;
            reportDb.Entry(reportDealerSale).State = EntityState.Modified;
            SaleReport  reportCustomerSale = allReports.First(x => x.SaleType == SaleType.CustomerSale);
            List <Sale> customerSalesToday = salesToday.Where(x => x.IsDealerSale == false).ToList();

            CalculateAmounts(reportCustomerSale, customerSalesToday);
            reportCustomerSale.Modified = DateTime.Now;
            reportDb.Entry(reportCustomerSale).State = EntityState.Modified;
            reportDb.SaveChanges();
            return(true);
        }