Пример #1
0
        public string UpdateStatus(int id, int status)
        {
            try
            {
                if (id == 0)
                {
                    return("Mã không tồn tại!");
                }

                if (_appoinmentBusiness.UpdateStatus(id, status))
                {
                    _appoinmentBusiness.Save();
                }
                return("");
            }
            catch (Exception)
            {
                return("Đã xảy ra lỗi!");
            }
        }
Пример #2
0
        public ActionResult Payment(PaymentParam model)
        {
            try
            {
                HttpCookie          reqCookies = Request.Cookies["MemberLoginCookie"];
                ResponseMemberLogin login      = JsonConvert.DeserializeObject <ResponseMemberLogin>(reqCookies.Value.ToString().UrlDecode());
                if (login == null || login.ID == 0)
                {
                    return(Json(new PaymentResult {
                        Status = -1, Uri = ""
                    }));
                }

                double reduce = 0;

                var doctor = _doctorBusiness.GetByID(model.DoctorID);

                if (doctor != null && doctor.ID != 0)
                {
                    if (model.PCode != "")
                    {
                        var promotion = _promotionBusiness.ApplyPromotion(model.PCode);
                        if (promotion != null && promotion.ID != 0)
                        {
                            if (promotion.DoctorApply == "" || promotion.DoctorApply == null)
                            {
                                if (promotion.Type == 1)
                                {
                                    reduce = promotion.AmountReduced;
                                }
                                else
                                {
                                    reduce = (doctor.Price * promotion.PercentReduced) / 100;
                                }
                            }
                            else
                            {
                                if (promotion.DoctorApply.Contains(doctor.ID.ToString()))
                                {
                                    if (promotion.Type == 1)
                                    {
                                        reduce = promotion.AmountReduced;
                                    }
                                    else
                                    {
                                        reduce = (doctor.Price * promotion.PercentReduced) / 100;
                                    }
                                }
                            }
                        }
                    }

                    AppoinmentView appoinment = new AppoinmentView();
                    appoinment.Amount    = doctor.Price - reduce;
                    appoinment.Code      = $"{DateTime.Now.ToString("ddMMyy")}{RandomUtils.RandomString(6, 8, true, true, false)}";
                    appoinment.Date      = model.Date;
                    appoinment.Doctor    = doctor.ID;
                    appoinment.IsPayment = false;
                    appoinment.Patient   = login.ID;
                    appoinment.Price     = doctor.Price;
                    appoinment.Reduce    = reduce;
                    appoinment.Status    = 0;
                    appoinment.Time      = model.Time;

                    if (_appoinmentBusiness.Add(appoinment))
                    {
                        _appoinmentBusiness.Save();
                        if (model.TypePay == 1)
                        {
                            string uri = CreateRequestPaymentPort((appoinment.Amount * 100).ToString(), appoinment.Code, login.ID.ToString());
                            return(Json(new PaymentResult {
                                Status = 1, Uri = uri
                            }));
                        }
                        if (model.TypePay == 2)
                        {
                            string uri = CreateRequestPaymentPortGlobal((appoinment.Amount * 100).ToString(), appoinment.Code, login.ID.ToString());
                            return(Json(new PaymentResult {
                                Status = 1, Uri = uri
                            }));
                        }
                    }
                }
                return(Json(new PaymentResult {
                    Status = -1, Uri = ""
                }));
            }
            catch (Exception)
            {
                return(Json(new PaymentResult {
                    Status = -1, Uri = ""
                }));
            }
        }