Пример #1
0
        public object EditQueue(QueueClassResponse queue)
        {
            try
            {
                var customerQueue     = DB.Customers.Where(x => x.CustomerId == queue.customerId).FirstOrDefault();
                var CustomerQueueTemp = customerQueue.CustomerQueue;
                customerQueue.CustomerQueue = null;

                DB.SaveChanges();

                var queueToDelete = DB.CustomerQueues.Where(x => x.Id == CustomerQueueTemp).FirstOrDefault();
                if (queueToDelete != null)
                {
                    DB.CustomerQueues.Remove(queueToDelete);
                    DB.SaveChanges();
                }

                CustomerQueue queueClass = new CustomerQueue();
                string        day        = queue.customerQueueDate.Substring(0, 2);
                string        month      = queue.customerQueueDate.Substring(3, 2);
                string        year       = queue.customerQueueDate.Substring(6, 4);
                string        hour       = queue.customerQueueTime;
                string        date       = day + "-" + month + "-" + year;
                string        time       = hour;
                queueClass.QueueTime = time;
                queueClass.QueueDate = date;
                queueClass.Treatment = queue.customerTreatment;
                DB.CustomerQueues.Add(queueClass);
                DB.SaveChanges();
                var queueEntity = DB.CustomerQueues.Where(x => x.QueueDate == queue.customerQueueDate && x.QueueTime == queue.customerQueueTime).Select(x => x.Id).FirstOrDefault();
                DB.Customers.Where(x => x.CustomerId == queue.customerId).ToList().ForEach(x => x.CustomerQueue = queueEntity);
                DB.SaveChanges();
                return(new Response
                {
                    Status = "Success", Message = "Appointment Made!"
                });
            }
            catch (Exception ex)
            {
                throw;
            }
            return(new Response
            {
                Status = "Error", Message = "Fail"
            });
        }
Пример #2
0
 public object SetQueue(QueueClassResponse queue)
 {
     try
     {
         if (DB.Customers.Where(x => x.CustomerId == queue.customerId).Select(x => x.CustomerQueue).FirstOrDefault() != null)
         {
             return(new Response
             {
                 Status = "Exist", Message = "User already have an appointment."
             });
         }
         CustomerQueue queueClass = new CustomerQueue();
         string        day        = queue.customerQueueDate.Substring(0, 2);
         string        month      = queue.customerQueueDate.Substring(3, 2);
         string        year       = queue.customerQueueDate.Substring(6, 4);
         string        hour       = queue.customerQueueTime;
         string        date       = day + "-" + month + "-" + year;
         string        time       = hour;
         queueClass.QueueTime = time;
         queueClass.QueueDate = date;
         queueClass.Treatment = queue.customerTreatment;
         DB.CustomerQueues.Add(queueClass);
         DB.SaveChanges();
         int id = DB.CustomerQueues.Where(x => x.QueueDate == queue.customerQueueDate && x.QueueTime == queue.customerQueueTime).Select(x => x.Id).FirstOrDefault();
         var existingCustomer = DB.Customers.Where(x => x.CustomerId == queue.customerId).SingleOrDefault();
         existingCustomer.CustomerQueue = id;
         DB.SaveChanges();
         return(new Response
         {
             Status = "Success", Message = "Appointment Made!"
         });
     }
     catch (Exception ex)
     {
         throw;
     }
     return(new Response
     {
         Status = "Error", Message = "Fail"
     });
 }