public ActionResult SendSMS(DateTime FromDate, DateTime ToDate, string Total, string TotalCash, string TotalCard)
        {
            try
            {
                SendSMSRepository _repository = new SendSMSRepository();
                string            message = "", messageCash = "", messageCard = "";
                if (FromDate == ToDate)
                {
                    message     = string.Format("Doanh thu ngay {0} la: {1}d. ", ToDate.ToString("dd/MM/yyyy"), Total);
                    messageCash = string.Format("Tien mat la: {0}d. ", TotalCash);
                    messageCard = string.Format("So tien ca the la: {0}d. ", TotalCard);
                }
                else
                {
                    message     = string.Format("Doanh thu tu ngay {0} den ngay {1} la: {2}d. ", FromDate.ToString("dd/MM/yyyy"), ToDate.ToString("dd/MM/yyyy"), Total);
                    messageCash = string.Format("Tien mat la: {0}d. ", TotalCash);
                    messageCard = string.Format("So tien ca the la: {0}d. ", TotalCard);
                }

                AY_SMSCalendar smsModel = new AY_SMSCalendar()
                {
                    EndDate        = DateTime.Now,
                    isSent         = true,
                    NumberOfFailed = 0,
                    SMSContent     = message + messageCash + messageCard,
                    SMSTo          = "01229992778"
                };
                _context.Entry(smsModel).State = System.Data.Entity.EntityState.Added;
                _context.SaveChanges();
                _repository.SendSMSModel(smsModel);

                return(Json(new
                {
                    Success = true
                }));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    Success = false,
                    ErrorMessage = ex.Message
                }));
            }
        }
Beispiel #2
0
        public ActionResult SaveAddNewOrder(Daily_ChicCut_Pre_OrderModel model, List <Daily_ChicCut_Pre_OrderDetailViewModel> details = null)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        var currentTime = DateTime.Now;
                        model.CreatedDate = currentTime;
                        // model.CreatedUserId = currentAccount.UserName;
                        _context.Entry(model).State = System.Data.Entity.EntityState.Added;
                        _context.SaveChanges();

                        //decimal SumCOGSOfOrderDetail = 0;
                        string ServicesName = "";
                        int    count        = 0;
                        #region Chi tiết đơn hàng
                        if (details != null)
                        {
                            foreach (var item in details)
                            {
                                count++;
                                ServicesName += item.ServiceName;
                                if (count < details.Count)
                                {
                                    ServicesName += " ; ";
                                }
                                Daily_ChicCut_Pre_OrderDetailModel itemAdd = new Daily_ChicCut_Pre_OrderDetailModel()
                                {
                                    ServiceCategoryId = item.ServiceCategoryId,
                                    // COGS = COGSCal,
                                    MinPrice = item.MinPrice,
                                    MaxPrice = item.MaxPrice,
                                    Qty      = item.Qty,
                                    //UnitCOGS = COGSCal * item.Qty,
                                    MinUnitPrice = item.MinPrice * item.Qty,
                                    MaxUnitPrice = item.MaxPrice * item.Qty,
                                    PreOrderId   = model.PreOrderId
                                };
                                _context.Entry(itemAdd).State = System.Data.Entity.EntityState.Added;
                            }
                        }
                        #endregion
                        // model.SumCOGSOfOrderDetail = SumCOGSOfOrderDetail;
                        model.ServicesName          = ServicesName;
                        _context.Entry(model).State = System.Data.Entity.EntityState.Modified;
                        _context.SaveChanges();
                        model.PreOrderCode = (model.PreOrderId % 1000).ToString("D3");



                        #region // Gửi SMS cho khách hàng
                        SendSMSRepository SMSRepo = new SendSMSRepository();
                        string            name    = model.FullName.LastIndexOf(' ') > 0 ? model.FullName.Substring(model.FullName.LastIndexOf(' ') + 1) : model.FullName;
                        name = Library.ConvertToNoMarkString(name);
                        if (!string.IsNullOrEmpty(name))
                        {
                            name = name.First().ToString().ToUpper() + name.Substring(1).ToLower();
                        }
                        string mes = string.Format(
                            "Cam on {0} {1} dat hen tai Chic Cut, thoi gian hen la: {2:HH:mm dd/MM/yyyy}. {0} vui long den dung gio da hen.",
                            model.Gender.HasValue && model.Gender.Value ? "anh" : "chi",
                            name,
                            model.AppointmentTime
                            );
                        AY_SMSCalendar smsModel = new AY_SMSCalendar()
                        {
                            EndDate        = DateTime.Now,
                            isSent         = true,
                            NumberOfFailed = 0,
                            SMSContent     = mes,
                            SMSTo          = model.Phone
                        };
                        _context.Entry(smsModel).State = System.Data.Entity.EntityState.Added;
                        #endregion

                        _context.SaveChanges();

                        SMSRepo.SendSMSModel(smsModel);

                        _context.SaveChanges();
                        ts.Complete();
                        return(Content("success"));
                    }
                }
                else
                {
                    return(Content("Vui lòng kiểm tra lại thông tin không hợp lệ"));
                }
            }
            catch
            {
                return(Content("Xảy ra lỗi trong quá trình thêm mới đơn hàng"));
            }
        }
Beispiel #3
0
        //Xử lý đặt hàng
        public ActionResult BookingOrder(Daily_ChicCut_Pre_OrderViewModel orderModel, string Phone, DateTime BookingDate, List <int> ServiceNoteList)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(Phone) || string.IsNullOrEmpty(orderModel.FullName))
                {
                    return(Json(new { Message = "(*) Vui lòng nhập thông tin bắt buộc!" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    #region //Tìm khách hàng qua sđt
                    var customer = _context.CustomerModel.Where(p => p.Phone == Phone).FirstOrDefault();
                    //Không có KH trong Db => thêm mới
                    if (customer == null)
                    {
                        CustomerModel cus = new CustomerModel();
                        //Thêm những field bắt buộc vào CustomerModel
                        cus.CustomerLevelId       = 1;
                        cus.FullName              = orderModel.FullName;
                        cus.ShortName             = orderModel.FullName;
                        cus.Phone                 = orderModel.Phone;
                        cus.Gender                = orderModel.Gender;
                        cus.Actived               = true;
                        cus.RegDate               = DateTime.Now;
                        _context.Entry(cus).State = System.Data.Entity.EntityState.Added;
                        _context.SaveChanges();
                        orderModel.CustomerId = cus.CustomerId;
                    }
                    //Có KH trong Db => cập nhật tên, giới tính dựa vào sđt
                    else
                    {
                        orderModel.CustomerId          = customer.CustomerId;
                        customer.ShortName             = orderModel.FullName;
                        customer.Gender                = orderModel.Gender;
                        _context.Entry(customer).State = System.Data.Entity.EntityState.Modified;
                        _context.SaveChanges();
                    }
                    #endregion
                }


                //KH chưa chọn khung giờ
                if (orderModel.BookingTime == TimeSpan.Zero)
                {
                    return(Json(new { Message1 = "(*) Khung giờ chưa được chọn! Vui lòng chọn khung giờ phục vụ." }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    //Mỗi sđt chỉ đặt được một lần trong ngày
                    var preOrder = _context.Daily_ChicCut_Pre_OrderModel.Where(p => p.Phone == Phone && DbFunctions.TruncateTime(p.AppointmentTime) == BookingDate.Date).FirstOrDefault();
                    if (preOrder != null)
                    {
                        return(Json(new { Message2 = "Số điện thoại này đã được đặt trong ngày!" }, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        //KH đặt trước dịch vụ:
                        //- Cắt
                        //- Uốn
                        //- Duỗi
                        //- Nhuộm
                        List <string> ServiceNoteListString = new List <string>();
                        foreach (var item in ServiceNoteList)
                        {
                            string haircuts = item == 0 ? "Cắt" : (item == 1 ? "Uốn" : (item == 2 ? "Duỗi" : "Nhuộm"));
                            ServiceNoteListString.Add(haircuts);
                        }
                        orderModel.ServiceNote = String.Join(", ", ServiceNoteListString);

                        Daily_ChicCut_Pre_OrderModel order = new Daily_ChicCut_Pre_OrderModel();
                        //Thêm những field bắt buộc vào Daily_ChicCut_Pre_OrderModel
                        order.CustomerId   = orderModel.CustomerId;
                        order.FullName     = orderModel.FullName;
                        order.Gender       = orderModel.Gender;
                        order.Phone        = orderModel.Phone;
                        order.ServicesNote = orderModel.ServiceNote;
                        order.Note         = orderModel.Note;
                        //Đơn hàng đặt trước => OrderStatusId = 5
                        order.OrderStatusId = 5;
                        //Xử lý ngày giờ hẹn
                        orderModel.AppointmentTime = orderModel.BookingDate + orderModel.BookingTime;
                        order.AppointmentTime      = orderModel.AppointmentTime;
                        //Ngày giờ đặt
                        orderModel.CreatedDate = DateTime.Now;
                        order.CreatedDate      = orderModel.CreatedDate;
                        //Thêm vào Db
                        _context.Entry(order).State = System.Data.Entity.EntityState.Added;
                        _context.SaveChanges();
                        //Tạo số phiếu đặt từ PreOrderId
                        order.PreOrderCode = (order.PreOrderId % 1000).ToString("D3");

                        #region // Gửi SMS cho khách hàng
                        SendSMSRepository SMSRepo = new SendSMSRepository();
                        string            name    = order.FullName.LastIndexOf(' ') > 0 ? order.FullName.Substring(order.FullName.LastIndexOf(' ') + 1) : order.FullName;
                        name = Library.ConvertToNoMarkString(name);
                        if (!string.IsNullOrEmpty(name))
                        {
                            name = name.First().ToString().ToUpper() + name.Substring(1).ToLower();
                        }
                        string mes = string.Format(
                            "Cam on {0} {1} dat hen tai Chic Cut, thoi gian hen la: {2:HH:mm dd/MM/yyyy}. {0} vui long den dung gio da hen.",
                            order.Gender.HasValue && order.Gender.Value ? "anh" : "chi",
                            name,
                            order.AppointmentTime
                            );
                        AY_SMSCalendar smsModel = new AY_SMSCalendar()
                        {
                            EndDate        = DateTime.Now,
                            isSent         = true,
                            NumberOfFailed = 0,
                            SMSContent     = mes,
                            SMSTo          = order.Phone
                        };
                        _context.Entry(smsModel).State = System.Data.Entity.EntityState.Added;
                        #endregion
                        _context.SaveChanges();

                        SMSRepo.SendSMSModel(smsModel);

                        _context.SaveChanges();
                        return(Json(true, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            else
            {
                return(Json(false, JsonRequestBehavior.AllowGet));
            }
        }