コード例 #1
0
        public JsonResult SaveAppointment(int restaurantId, int tableId, string agendaEvent)
        {
            try
            {
                var appointment = CreateAppointmentFromEvent(restaurantId, tableId, agendaEvent);

                if (!AppointmentsHelper.CheckForOverlappingAppointments(appointment, _context))
                {
                    _context.Appointments.Add(appointment);
                    _context.SaveChanges();
                    //TwilloCommunication.SendMessageToClient("");
                    if (!string.IsNullOrEmpty(appointment.persEmail))
                    {
                        SmtpHelper.SendEmail(appointment, _context);
                    }

                    return(Json(new { success = true, responseText = appointment.Id }));
                }
                else
                {
                    return(Json(new { success = false, responseText = "overlapping" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, responseText = ex }));
            }
        }
        /// <summary>
        /// To Create an Order
        /// </summary>
        /// <param name="OrderModel"></param>
        /// <returns></returns>
        public bool AddOrder(OrderModel OrderModel)
        {
            try
            {
                using (var dbContext = new OrderManagementEntities())
                {
                    var OrderStatusParentID = 1;
                    var order    = new Order();
                    var items    = new List <Item>();
                    var products = new List <Product>();

                    var userInfo = ValidateUser(OrderModel.UserID, dbContext);
                    if (!userInfo.isBuyer)
                    {
                        throw new Exception("Invalid User");
                    }
                    order.UserID = userInfo.Id;

                    var orderState = GetLookupValues(OrderStatusParentID, dbContext).FirstOrDefault(x => x.UUID == OrderModel.OrderState);
                    if (orderState == null)
                    {
                        throw new Exception("Invalid Order Status");
                    }

                    order.OrderState      = orderState.Id;
                    order.ShippingAddress = OrderModel.ShippingAddress;
                    order.Items           = xmlSerialize(OrderModel.Items, dbContext, ref products);
                    order.UUID            = Guid.NewGuid();
                    dbContext.Orders.Add(order);
                    dbContext.SaveChanges();

                    //Sending Email To The User
                    SmtpHelper.SendEmail(userInfo.Email, userInfo.UserName);
                    //Updating Available Quantity of products
                    UpdateProductsAvailableQuantity(products);

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }