コード例 #1
0
        public async Task<IHttpActionResult> PostOrders(Guid id, OrderInsertEvent order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != order.UniqueID)
            {
                return BadRequest();
            }

            Order orderFromdb = await db.Orders.Where(x => x.UniqueID == order.UniqueID).FirstOrDefaultAsync();

            db.OrderDetails.RemoveRange(orderFromdb.OrderDetails);

            orderFromdb.FirstName = order.FirstName;
            orderFromdb.LastName = order.LastName;

            var services = db.Services.Where(x => order.Services.Contains(x.ServiceID));
            long serviceTicks = 0;

            foreach (var item in services)
            {
                db.OrderDetails.Add(new OrderDetail
                {
                    DontCare = false,
                    EmployeeID = order.EmployeeID,
                    Price = item.Price,
                    ServiceID = item.ServiceID,
                    OrderID = orderFromdb.OrderID
                });

                serviceTicks += item.Time.Ticks;
            }

            DateTime iKnowThisIsUtc = order.StartDateTime;
            DateTime runtimeKnowsThisIsUtc = DateTime.SpecifyKind(
                iKnowThisIsUtc,
                DateTimeKind.Utc);
            var localVersion = TimeZoneInfo.ConvertTimeFromUtc(runtimeKnowsThisIsUtc, TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time"));//offset.ToOffset(new TimeSpan(3, 0, 0));


            orderFromdb.Date = localVersion.Date;
            orderFromdb.StartDateTime = localVersion;

            DateTime endDt = localVersion;
            TimeSpan startTime = new TimeSpan(), endTime = new TimeSpan();

            var servicesTotalTime = serviceTicks;

            startTime = new TimeSpan(endDt.Hour, endDt.Minute, 0);
            endTime = new TimeSpan(startTime.Ticks + servicesTotalTime);

            endDt = endDt.AddTicks(servicesTotalTime);

            orderFromdb.EndDateTime = endDt;
            orderFromdb.StartTime = startTime;
            orderFromdb.EndTime = endTime;

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

            try
            {
                await db.SaveChangesAsync();

            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
コード例 #2
0
        public async Task<IHttpActionResult> PostOrders(OrderInsertEvent order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Order newO = new Order();

            newO.FirstName = order.FirstName;
            newO.LastName = order.LastName;
            newO.SalonID = order.SalonID;
            newO.UserName = order.UserName;
            newO.CreateOn = getTime;
            newO.UniqueID = Guid.NewGuid();
            newO.IsFromAdmin = true;

            var services = db.Services.Where(x => order.Services.Contains(x.ServiceID));
            List<OrderDetail> details = new List<OrderDetail>();
            long serviceTicks = 0;

            foreach (var item in services)
            {
                details.Add(new OrderDetail
                {
                    DontCare = false,
                    EmployeeID = order.EmployeeID,
                    Price = item.Price,
                    ServiceID = item.ServiceID
                });

                serviceTicks += item.Time.Ticks;
            }

            newO.OrderDetails = details;

            DateTime iKnowThisIsUtc = order.StartDateTime;
            DateTime runtimeKnowsThisIsUtc = DateTime.SpecifyKind(
                iKnowThisIsUtc,
                DateTimeKind.Utc);
            var localVersion = TimeZoneInfo.ConvertTimeFromUtc(runtimeKnowsThisIsUtc, TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time"));//offset.ToOffset(new TimeSpan(3, 0, 0));


            newO.Date = localVersion.Date;
            newO.StartDateTime = localVersion;

            DateTime endDt = localVersion;
            TimeSpan startTime = new TimeSpan(), endTime = new TimeSpan();

            var servicesTotalTime = serviceTicks;

            startTime = new TimeSpan(endDt.Hour, endDt.Minute, 0);
            endTime = new TimeSpan(startTime.Ticks + servicesTotalTime);

            endDt = endDt.AddTicks(servicesTotalTime);

            newO.EndDateTime = endDt;
            newO.StartTime = startTime;
            newO.EndTime = endTime;


            db.Orders.Add(newO);
            await db.SaveChangesAsync();

            return Ok(newO.UniqueID);
        }