Example #1
0
        public async Task<IHttpActionResult> PutOrder(int id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

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

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Example #2
0
        public async Task<IHttpActionResult> PostOrder(OrderInsert order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            Order newO = new Order()
            {
                FirstName = order.FirstName,
                LastName = order.LastName,
                StartTime = order.StartTime,
                EndTime = order.EndTime,
                Phone = order.Phone,
                SalonID = order.SalonID,
                Sex = order.Sex,
                UserName = order.UserName,
                OrderDetails = order.Services,
                CreateOn = DateTime.Now,
                Date = order.Date
            };

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

            return CreatedAtRoute("DefaultApi", new { id = newO.OrderID }, newO);
        }
Example #3
0
        public async Task<IHttpActionResult> ChangeTime(Guid id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            Order orderFromdb = await db.Orders.FindAsync(order.OrderID);

            orderFromdb.Date = order.Date.Date;
            orderFromdb.StartDateTime = order.StartDateTime.ToLocalTime();

            DateTime endDt = order.StartDateTime.ToLocalTime();
            TimeSpan startTime = new TimeSpan(), endTime = new TimeSpan();

            var servicesTotalTime = orderFromdb.OrderDetails.Sum(x => x.Service.Time.Ticks);

            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();
                order.Date = orderFromdb.Date;
                order.StartDateTime = orderFromdb.StartDateTime;
                order.EndDateTime = orderFromdb.EndDateTime;
                order.StartTime = orderFromdb.StartTime;
                order.EndTime = orderFromdb.EndTime;
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return Ok(order);
        }
Example #4
0
        public async Task<IHttpActionResult> PutOrder(Guid id, Order order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            Order orderFromdb = await db.Orders.FindAsync(order.OrderID);

            if (order.RejectedByUser)
            {
                if (!orderFromdb.Accepted && !orderFromdb.Rejected && !orderFromdb.DidntCome && !orderFromdb.Finished && !orderFromdb.RejectedByUser)
                {
                    orderFromdb.RejectedByUser = true;
                    orderFromdb.RejectedByUserTime = getTime;
                    orderFromdb.RejectedByUserReason = order.RejectedByUserReason;
                    orderFromdb.RejectedBy = order.RejectedBy;

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

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                }
                else
                {
                    return StatusCode(HttpStatusCode.Conflict);
                }
            }

            if (order.Rejected && !order.Finished && !order.DidntCome)
            {
                if (!orderFromdb.Accepted && !orderFromdb.Rejected && !orderFromdb.DidntCome && !orderFromdb.Finished && !orderFromdb.RejectedByUser)
                {
                    orderFromdb.Rejected = true;
                    orderFromdb.RejectedTime = getTime;

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

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                }
                else
                {
                    return StatusCode(HttpStatusCode.Conflict);
                }
            }

            if (order.Accepted && !order.Finished && !order.DidntCome)
            {
                if (!orderFromdb.Accepted && !orderFromdb.Rejected && !orderFromdb.DidntCome && !orderFromdb.Finished && !orderFromdb.RejectedByUser)
                {
                    orderFromdb.Accepted = true;
                    orderFromdb.AcceptedTime = getTime;

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

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                }
                else
                {
                    return StatusCode(HttpStatusCode.Conflict);
                }
            }

            if (order.Accepted && order.Finished && !order.DidntCome)
            {
                if (orderFromdb.Accepted && !orderFromdb.Rejected && !orderFromdb.DidntCome && !orderFromdb.Finished && !orderFromdb.RejectedByUser)
                {
                    orderFromdb.Finished = true;

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

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                }
                else
                {
                    return StatusCode(HttpStatusCode.Conflict);
                }
            }

            if (order.Accepted && !order.Finished && order.DidntCome)
            {
                if (orderFromdb.Accepted && !orderFromdb.Rejected && !orderFromdb.DidntCome && !orderFromdb.Finished && !orderFromdb.RejectedByUser)
                {
                    orderFromdb.DidntCome = true;

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

                    try
                    {
                        await db.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                }
                else
                {
                    return StatusCode(HttpStatusCode.Conflict);
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Example #5
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);
        }
Example #6
0
        public async Task<IHttpActionResult> PostOrders(OrderInsert order)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            Order newO = new Order()
            {
                FirstName = order.FirstName,
                LastName = order.LastName,
                StartTime = order.StartTime,
                EndTime = order.EndTime,
                Phone = order.Phone,
                SalonID = order.SalonID,
                Sex = order.Sex,
                UserName = order.UserName,
                OrderDetails = order.Services,
                CreateOn = getTime,
                Date = localVersion,
                StartDateTime = localVersion.Add(order.StartTime),
                EndDateTime = localVersion.Add(order.EndTime),
                MoreInfo = order.MoreInfo,
                UniqueID = Guid.NewGuid(),
            };

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

            return CreatedAtRoute("DefaultApi", new { id = newO.OrderID }, newO);
        }