private void HandleUnauthorizedRequest(AuthorizationContext filterContext, MethodInfo methodInfo, Exception exception)
        {
            filterContext.HttpContext.Response.StatusCode =
                filterContext.RequestContext.HttpContext.User?.Identity?.IsAuthenticated ?? false
                   ? (int)HttpStatusCode.Forbidden
                   : (int)HttpStatusCode.Unauthorized;

            var isAjax = filterContext.HttpContext.Request.IsAjaxRequest();

            if (isAjax)
            {
                filterContext.Result = new JsonResult()
                {
                    Data = AjaxResult.Fail("")
                };
            }
            else
            {
                //返回错误页面
                //filterContext.Result = CreateUnAuthorizedNonJsonResult(filterContext, ex);
            }

            if (isAjax)
            {
                filterContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true;
            }
        }
Esempio n. 2
0
        public ActionResult Delete(int id = 0)
        {
            var menus = _menuDal.GetAll <Menu>();

            if (menus.FirstOrDefault(p => p.MenuParentId == id) != null)
            {
                return(Json(AjaxResult.Fail("请先删除子菜单")));
            }

            var m = menus.FirstOrDefault(p => p.Id == id);

            if (m != null)
            {
                var result = DeleteWXMenu(m);
                if (!string.IsNullOrEmpty(result))
                {
                    return(Json(AjaxResult.Fail(result)));
                }

                _menuDal.Delete(new Menu {
                    Id = id
                });
            }


            return(Json(AjaxResult.Success()));
        }
Esempio n. 3
0
        public ActionResult SendVideoComment(int VideoId = 0, string Comment = "")
        {
            var comment = new VideoComment {
                VideoId = VideoId, Comment = Comment
            };

            if (comment.VideoId <= 0)
            {
                return(Json(AjaxResult.Fail("请求失败")));
            }

            if (string.IsNullOrEmpty(comment.Comment))
            {
                return(Json(AjaxResult.Fail("请填写评论")));
            }

            var vip = GetVipInfo();

            comment.CreatedBy   = vip.VipName;
            comment.CreatedTime = DateTime.Now;
            comment.UpdatedBy   = vip.VipName;
            comment.UpdatedTime = DateTime.Now;
            comment.VipId       = vip.Id;
            comment.VipImgPath  = vip.ImgPath;
            comment.VipName     = vip.VipName;

            dal.Insert(comment);

            return(Json(AjaxResult.Success()));
        }
Esempio n. 4
0
        public void GetRoomList(int wid, string openid, int hotelId)
        {
            AjaxResult ajaxResult;

            try
            {
                GetRoomListResponse responseData = null;
                IAsyncResult        asyncResult  = new BusEntry("WeixinPF.Hotel.Plugins").MyBus.Send("WeixinPF.Hotel.Plugins.Service",
                                                                                                     new GetRoomListRequest()
                {
                    HotelId = hotelId
                })
                                                   .Register(response =>
                {
                    CompletionResult result = response.AsyncState as CompletionResult;
                    if (result != null)
                    {
                        responseData = result.Messages[0] as GetRoomListResponse;
                    }
                }, this);

                WaitHandle asyncWaitHandle = asyncResult.AsyncWaitHandle;
                asyncWaitHandle.WaitOne(WaitSeconds);

                ajaxResult = asyncResult.IsCompleted ?
                             AjaxResult.Succeed(responseData.Rooms) :
                             AjaxResult.Fail("获取房间列表失败。");
            }
            catch
            {
                ajaxResult = AjaxResult.Fail("获取房间列表失败。");
            }

            this.WriteJson(ajaxResult);
        }
Esempio n. 5
0
        public ActionResult SendSms(string mobile)
        {
            var err = string.Empty;

            if (string.IsNullOrEmpty(mobile))
            {
                return(Json(AjaxResult.Fail("手机号为空"), JsonRequestBehavior.AllowGet));
            }

            //判断手机号是否注册
            var user = _dal.GetByMobile(mobile);

            if (user != null)
            {
                return(Json(AjaxResult.Fail("手机号已存在"), JsonRequestBehavior.AllowGet));
            }

            Random rd  = new Random();
            int    num = rd.Next(100000, 999999);

            Session["VerCode"] = num;
            Session["PhoneNo"] = mobile;
            //SendSMS.Send(PhoneNo, num);
            return(Json(AjaxResult.Success(num.ToString()), JsonRequestBehavior.AllowGet));
        }
Esempio n. 6
0
        public ActionResult AddOrEdit(Notice model)
        {
            if (ModelState.IsValid)
            {
                if (model.Id == 0)
                {
                    model.PublishUser = CurrentUser.UserName;
                    model.CreatedBy   = CurrentUser.UserName;
                    model.UpdatedBy   = CurrentUser.UserName;

                    _dal.Insert(model);
                }
                else
                {
                    var entity = _dal.Get <Notice>(model.Id);
                    if (entity != null)
                    {
                        entity.Title       = model.Title;
                        entity.Content     = model.Content;
                        entity.ImgPath     = model.ImgPath;
                        entity.UpdatedTime = DateTime.Now;

                        _dal.Update(entity);
                    }
                }
                return(Json(AjaxResult.Success()));
            }
            else
            {
                var erros = GetModelErrors();
                return(Json(AjaxResult.Fail(erros)));
            }
        }
Esempio n. 7
0
        public ActionResult AddOrEdit(Menu model)
        {
            if (ModelState.IsValid)
            {
                if (model.Id == 0)
                {
                    //创建微信菜单
                    var result = CreateWXMenu(model);
                    if (!string.IsNullOrEmpty(result))
                    {
                        return(Json(AjaxResult.Fail(result)));
                    }

                    if (model.MenuParentId > 0)
                    {
                        var pMenu = _menuDal.Get <Menu>(model.MenuParentId);
                        model.MenuParentName = pMenu?.MenuName;
                    }
                    model.CreatedBy = CurrentUser.UserName;
                    model.UpdatedBy = CurrentUser.UserName;

                    _menuDal.Insert(model);
                }
                else
                {
                    //创建微信菜单
                    var result = CreateWXMenu(model);
                    if (!string.IsNullOrEmpty(result))
                    {
                        return(Json(AjaxResult.Fail(result)));
                    }

                    var entity = _menuDal.Get <Menu>(model.Id);
                    if (entity != null)
                    {
                        entity.MenuLevel    = model.MenuLevel;
                        entity.MenuName     = model.MenuName;
                        entity.MenuParentId = model.MenuParentId;
                        if (model.MenuParentId > 0)
                        {
                            var pMenu = _menuDal.Get <Menu>(model.MenuParentId);
                            entity.MenuParentName = pMenu?.MenuName;
                        }
                        entity.Url         = model.Url;
                        entity.UpdatedTime = DateTime.Now;

                        _menuDal.Update(entity);
                    }
                }
                return(Json(AjaxResult.Success()));
            }
            else
            {
                var erros = GetModelErrors();
                return(Json(AjaxResult.Fail(erros)));
            }
        }
Esempio n. 8
0
        public AjaxResult ThemGiaoDich(int hoaDonID, int soTien, string ngayGiaoDich)
        {
            IHoaDonRepository hoaDonRepository = uow.Repository <HoaDonRepository>();
            var model = hoaDonRepository.GetHoaDonModelByID(hoaDonID);

            if (model == null)
            {
                return(AjaxResult.Fail("Hóa đơn không tồn tại. Vui lòng tải lại trang.", true));
            }

            if (model.CoDuNoQuaHan)
            {
                return(AjaxResult.Fail("Khách hàng có dư nợ quá hạn cần thanh toán trước.", true));
            }

            var current = DateTime.Now.AddMonths(-1);

            if (!(!model.CoDuNoQuaHan && // không có dư nợ & (tháng hiện tại || (< tháng hiện tại & chưa thu))
                  ((model.HoaDon.ThangHoaDon == current.Month && model.HoaDon.NamHoaDon == current.Year) ||
                   ((model.HoaDon.NamHoaDon < current.Year || (model.HoaDon.NamHoaDon == current.Year && model.HoaDon.ThangHoaDon < current.Month)) &&
                    (model.HoaDon.Trangthaithu == false || model.HoaDon.Trangthaithu == null)))))
            {
                return(AjaxResult.Fail("Không thể thêm giao dịch cho hóa đơn này. Dữ liệu bất đồng bộ, vui lòng load lại trang.", true));
            }

            DateTime dt;

            if (!DateTime.TryParseExact(ngayGiaoDich, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
            {
                dt = DateTime.Now;
            }

            if (!GiaoDichHelpers.ThemGiaoDich(model, soTien, dt, uow))
            {
                return(AjaxResult.Fail("Lỗi thêm giao dịch. Vui lòng thử lại."));
            }

            int duNo = (int)(model.SoTienNopTheoThang.SoTienPhaiNop - model.SoTienNopTheoThang.SoTienDaThu);

            return(AjaxResult.Success("Giao dịch thành công.", false,
                                      new
            {
                HoaDon = new
                {
                    ID = model.HoaDon.HoadonnuocID,
                    TrangThaiThu = model.HoaDon.Trangthaithu,
                    NgayNopTien = model.HoaDon.NgayNopTien != null ? model.HoaDon.NgayNopTien.Value.ToString("dd/MM/yyyy") : ""
                },
                SoTienNopTheoThang = new
                {
                    SoTienDaThu = CurrencyHelpers.FormatVN(model.SoTienNopTheoThang.SoTienDaThu ?? 0),
                    DuNo = CurrencyHelpers.FormatVN(duNo > 0 ? duNo : -duNo)
                }
            }));
        }
Esempio n. 9
0
 public ActionResult Edit(EditRoleModel model)
 {
     if (ModelState.IsValid)
     {
         _roleService.EditRole(model);
         return(Json(AjaxResult.Success()));
     }
     else
     {
         var erros = GetModelErrors();
         return(Json(AjaxResult.Fail(erros)));
     }
 }
Esempio n. 10
0
 public ActionResult Add(AddRoleModel addRoleModel)
 {
     if (ModelState.IsValid)
     {
         addRoleModel.CreatedBy = CurrentUser.LoginName;
         _roleService.AddRole(addRoleModel);
         return(Json(AjaxResult.Success()));
     }
     else
     {
         var erros = GetModelErrors();
         return(Json(AjaxResult.Fail(erros)));
     }
 }
Esempio n. 11
0
 public ActionResult Edit(User model)
 {
     if (ModelState.IsValid)
     {
         model.UpdatedBy = CurrentUser.LoginName;
         _userService.Edit(model);
         return(Json(AjaxResult.Success()));
     }
     else
     {
         var erros = GetModelErrors();
         return(Json(AjaxResult.Fail(erros)));
     }
 }
Esempio n. 12
0
        public ActionResult Delete(int functionid = -1)
        {
            var count = _funService.GetChildFunction(functionid);

            if (count > 0)
            {
                return(Json(AjaxResult.Fail("该功能下还有子功能,无法删除")));
            }

            _funService.Delete(new PermissionModel {
                Id = functionid
            });
            return(Json(AjaxResult.Success()));
        }
Esempio n. 13
0
 public ActionResult Add(PermissionModel model)
 {
     if (ModelState.IsValid)
     {
         model.CreatedBy = CurrentUser.LoginName;
         model.UpdatedBy = CurrentUser.LoginName;
         _funService.AddFunction(model);
         return(Json(AjaxResult.Success()));
     }
     else
     {
         var erros = GetModelErrors();
         return(Json(AjaxResult.Fail(erros)));
     }
 }
Esempio n. 14
0
        /// <summary>
        /// thanh toán hóa đơn vs ID đã cho
        /// nếu ngày nộp không đúng > ngày nộp = ngày hiện tại
        /// </summary>
        /// <effects>
        ///     get HoaDonModel <tt>model</tt> with specified <tt>hoaDonID</tt>
        ///     if model == null || model.HoaDon.TrangThaiThu == true
        ///         throw NotPossibleException: Dữ liệu bất đồng bộ, vui lòng refresh lại trang
        ///     invoke @{link HoaDonHelpers#ThemGiaoDich(HoaDonModel)}: thanh toan HoaDonModel
        /// </effects>
        public AjaxResult ThanhToan(int hoaDonID, string ngayThu)
        {
            var model = hoaDonRepository.GetHoaDonModelByID(hoaDonID);

            if (model == null || model.HoaDon.Trangthaithu == true)
            {
                return(AjaxResult.Fail("Dữ liệu bất đồng bộ, vui lòng refresh lại trang.", true));
            }

            try
            {
                DateTime dt;
                if (!DateTime.TryParseExact(ngayThu, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    dt = DateTime.Now;
                }

                if (!HoaDonHelpers.ThanhToan(model, dt, uow))
                {
                    return(AjaxResult.Fail("Lỗi cập nhật dữ liệu. Vui lòng thử lại."));
                }
            }
            catch (Exception e)
            {
                return(AjaxResult.Fail(e.Message));
            }

            int duNo = (int)(model.SoTienNopTheoThang.SoTienPhaiNop - model.SoTienNopTheoThang.SoTienDaThu);

            return(AjaxResult.Success("Thanh toán thành công.",
                                      (model.HoaDon.ThangHoaDon != current.Month && model.HoaDon.NamHoaDon != current.Year),
                                      new
            {
                HoaDon = new
                {
                    ID = model.HoaDon.HoadonnuocID,
                    TrangThaiThu = model.HoaDon.Trangthaithu,
                    NgayNopTien = model.HoaDon.NgayNopTien != null ? model.HoaDon.NgayNopTien.Value.ToString("dd/MM/yyyy") : ""
                },
                SoTienNopTheoThang = new
                {
                    SoTienDaThu = CurrencyHelpers.FormatVN(model.SoTienNopTheoThang.SoTienDaThu ?? 0),
                    DuNo = CurrencyHelpers.FormatVN(duNo > 0 ? duNo : -duNo)
                }
            }));
        }
Esempio n. 15
0
        /// <summary>
        /// Hủy giao dịch với ID đã cho
        /// </summary>
        /// <effects>
        /// if giaoDich with specified giaoDichID not exist
        ///     throw NotFoundException: Dữ liệu bất đồng bộ. Vui lòng tải lại trang.
        /// if lastGiaoDich.ID == giaoDichID
        ///     invoke @{link #HuyGiaoDich}: roll back lastGiaoDich
        /// </effects>
        public AjaxResult HuyGiaoDich(int khachHangID, int giaoDichID)
        {
            IGiaoDichRepository giaoDichRepository = uow.Repository <GiaoDichRepository>();

            var model = giaoDichRepository.GetLastGiaoDichByKHID(khachHangID);

            if (model == null || model.GiaoDich.GiaoDichID != giaoDichID)
            {
                return(AjaxResult.Fail("Dữ liệu bất đồng bộ. Vui lòng tải lại trang.", true));
            }

            if (!GiaoDichHelpers.HuyGiaoDich(model, uow))
            {
                return(AjaxResult.Fail("Lỗi hủy giao dịch. Vui lòng thử lại."));
            }

            return(AjaxResult.Success("Hủy giao dịch thành công.", true));
        }
Esempio n. 16
0
        public override void OnException(ExceptionContext filterContext)
        {
            //1.如果异常已经处理,那么就不管了
            if (filterContext.ExceptionHandled)
            {
                return;
            }

            //2.如果异常没有处理,那么就返回错误结果,及对于的错误页面
            string controllerName = filterContext.RouteData.Values["controller"].ToString();
            string actionName     = filterContext.RouteData.Values["action"].ToString();
            //找到当前登陆人的登陆信息
            //string userData = filterContext.HttpContext.Request.Cookies["userData"].Value;

            //3:记录错误信息
            Exception     ex    = filterContext.Exception;
            StringBuilder sbMsg = new StringBuilder();

            while (ex != null)
            {
                sbMsg.AppendFormat("控制器:{0},方法:{1}:错误信息:{2}", controllerName, actionName, ex.Message.ToString());
                ex = ex.InnerException;
            }
            _logger.ErrorFormat(sbMsg.ToString());
            //4:处理错误信息
            //4.1 如果是ajax请求,返回错误信息
            if (filterContext.HttpContext.Request.IsAjaxRequest())
            {
                filterContext.Result = new JsonResult()
                {
                    Data = AjaxResult.Fail(sbMsg.ToString())
                };
            }
            //4.2 如果是页面请求,那么就跳转到错误页面
            else
            {
                filterContext.Result = new RedirectResult("/Home/Error");
            }

            base.OnException(filterContext);
        }
Esempio n. 17
0
 public ActionResult AddOrEdit(Vip model)
 {
     if (ModelState.IsValid)
     {
         var entity = _dal.Get <Vip>(model.Id);
         if (entity != null)
         {
             entity.Password = model.Password;
             //entity.CardImg = model.CardImg;
             entity.CertNo  = model.CertNo;
             entity.HasCert = model.HasCert;
             _dal.Update(entity);
         }
         return(Json(AjaxResult.Success()));
     }
     else
     {
         var erros = GetModelErrors();
         return(Json(AjaxResult.Fail(erros)));
     }
 }
Esempio n. 18
0
        public void SaveOrder(int wid, string openid, int hotelId, int roomId, string roomType, string order)
        {
            AjaxResult ajaxResult;

            try
            {
                CreateOrderResponse responseData = null;
                CreateOrderRequest  request      = new CreateOrderRequest()
                {
                    Wid      = wid,
                    OpenId   = openid,
                    HotelId  = hotelId,
                    RoomId   = roomId,
                    RoomType = roomType,
                    Order    = JSONHelper.Deserialize <OrderDto>(order)
                };
                IAsyncResult asyncResult = new BusEntry("WeixinPF.Hotel.Plugins").MyBus.Send("WeixinPF.Hotel.Plugins.Service", request)
                                           .Register(response =>
                {
                    CompletionResult result = response.AsyncState as CompletionResult;
                    if (result != null)
                    {
                        responseData = result.Messages[0] as CreateOrderResponse;
                    }
                }, this);

                WaitHandle asyncWaitHandle = asyncResult.AsyncWaitHandle;
                asyncWaitHandle.WaitOne(WaitSeconds);

                ajaxResult = asyncResult.IsCompleted ?
                             AjaxResult.Succeed(responseData.OrderId) :
                             AjaxResult.Fail("保存订失败。");
            }
            catch
            {
                ajaxResult = AjaxResult.Fail("保存订失败。");
            }

            this.WriteJson(ajaxResult);
        }
Esempio n. 19
0
        /// <summary>
        /// 登陆验证
        /// </summary>
        /// <param name="account"></param>
        /// <param name="plainPassword"></param>
        /// <param name="isRemember"></param>
        /// <returns></returns>
        protected virtual async Task <AjaxResult> LoginAsyncInternal(string account, string plainPassword, bool isRemember)
        {
            if (account.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(account));
            }

            if (plainPassword.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(plainPassword));
            }


            Sys_Account user = await _accountRepository.FirstOrDefaultAsync(u => u.Account.Equals(account));

            //1.检查人员是否存在
            if (user == null)
            {
                return(AjaxResult.Fail(LoginPrompt.AccountNotExisit));
            }
            //2.账号未被激活
            if (!user.IsActive)
            {
                return(AjaxResult.Fail(LoginPrompt.DisableAccount));
            }
            //3.检查密码是否正常
            if (user.Password != plainPassword)
            {
                return(AjaxResult.Fail(LoginPrompt.PwdError));
            }
            //3.检查账户是否有授权

            if (await userRoleRepository.FirstOrDefaultAsync(u => u.UserId.Equals(user.Id)) == null)
            {
                return(AjaxResult.Fail(LoginPrompt.NoGrant));
            }

            return(await CreateLoginResultAsync(user, isRemember));
        }
Esempio n. 20
0
        public ActionResult AddOrEdit(VideoComment model)
        {
            if (ModelState.IsValid)
            {
                var entity = _dal.Get <VideoComment>(model.Id);
                if (entity != null)
                {
                    entity.Reply        = model.Reply;
                    entity.ReplyAdminId = CurrentUser.Id;
                    entity.ReplyTime    = DateTime.Now;
                    entity.UpdatedTime  = DateTime.Now;

                    _dal.Update(entity);
                }
                return(Json(AjaxResult.Success()));
            }
            else
            {
                var erros = GetModelErrors();
                return(Json(AjaxResult.Fail(erros)));
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Hủy thanh toán hóa đơn vs ID đã cho
        /// </summary>
        /// <effects>
        ///     get HoaDonModel <tt>model</tt> with specified <tt>hoaDonID</tt>
        ///     if model == null || model.TrangThaiThu == false
        ///         throw NotPossibleException: Dữ liệu bất đồng bộ, vui lòng refresh lại trang
        ///     if model.SoTienPhaiNop.SoTienDaThu == 0
        ///         throw NotPossibleException: Khách hàng thanh toán trừ dư có
        ///     if model.KhachHang.HinhThucThanhToan == ChuyenKhoan
        ///         throw NotPossibleException: Khách hàng thanh toán qua chuyển khoản
        ///     if lastGiaoDich.NgayThu == model.HoaDon.NgayThu && lastGiaoDich.SoTien == model.SoTienNopTheoThang.SoTienDaThu
        ///         invoke @{link #HuyGiaoDich()}: huy giao dich gan nhat
        ///     throw NotPossibleException: Không thể hủy thanh toán! Vui lòng hủy giao dịch tại Xem lịch sử giao dịch.
        /// </effects>
        public AjaxResult HuyThanhToan(int hoaDonID)
        {
            var model = hoaDonRepository.GetHoaDonModelByID(hoaDonID);

            if (model == null || model.HoaDon.Trangthaithu == false || model.HoaDon.Trangthaithu == null)
            {
                return(AjaxResult.Fail("Dữ liệu bất đồng bộ, vui lòng refresh lại trang.", true));
            }

            try
            {
                if (!HoaDonHelpers.HuyThanhToan(model, uow))
                {
                    return(AjaxResult.Fail("Lỗi cập nhật dữ liệu. Vui lòng thử lại."));
                }
            }
            catch (Exception e)
            {
                return(AjaxResult.Fail(e.Message));
            }

            int duNo = (int)(model.SoTienNopTheoThang.SoTienPhaiNop - model.SoTienNopTheoThang.SoTienDaThu);

            return(AjaxResult.Success("Hủy thanh toán thành công.", false,
                                      new
            {
                HoaDon = new
                {
                    ID = model.HoaDon.HoadonnuocID,
                    TrangThaiThu = model.HoaDon.Trangthaithu,
                    NgayNopTien = model.HoaDon.NgayNopTien != null ? model.HoaDon.NgayNopTien.Value.ToString("dd/MM/yyyy") : ""
                },
                SoTienNopTheoThang = new
                {
                    SoTienDaThu = CurrencyHelpers.FormatVN(model.SoTienNopTheoThang.SoTienDaThu ?? 0),
                    DuNo = CurrencyHelpers.FormatVN(duNo > 0 ? duNo : -duNo)
                }
            }));
        }
Esempio n. 22
0
        public ActionResult UploadImg(string serverId = "")
        {
            if (!string.IsNullOrEmpty(serverId))
            {
                var token    = AccessTokenContainer.TryGetAccessToken(AppConfig.Instance.AppId, AppConfig.Instance.AppSecret);
                var fileName = $"/upload/cardimg/{Guid.NewGuid().ToString("N")}.jpg";
                Senparc.Weixin.MP.AdvancedAPIs.MediaApi.Get(token, serverId, Server.MapPath("~" + fileName));

                var vip = GetVipInfo();
                vip.ImgPath     = fileName;
                vip.UpdatedTime = DateTime.Now;

                _dal.Update(vip);

                _dal.UpdateCommentsVipImg(vip);

                return(Json(AjaxResult.Success()));
            }
            else
            {
                return(Json(AjaxResult.Fail("请上传图片")));
            }
        }
Esempio n. 23
0
        public ActionResult MpConfig(MpConfigModel config, int id = 0)
        {
            //if (config.PayDateRange != null && config.PayDateRange.StartDate != null && config.PayDateRange.EndDate != null)
            //{
            //    if (config.PayDateRange.StartDate > config.PayDateRange.EndDate)
            //    {
            //        return Json(AjaxResult.Fail("开始缴费日期不能大于结束日期"));
            //    }
            //}

            if (config.RejoinTeamStartDate != null && config.RejoinTeamEndDate != null)
            {
                if (config.RejoinTeamStartDate > config.RejoinTeamEndDate)
                {
                    return(Json(AjaxResult.Fail("重新加入球队开始日期不能大于结束日期")));
                }
            }

            if (id == 0)
            {
                _menuDal.Insert(new MPConfig {
                    ConfigValue = JsonConvert.SerializeObject(config)
                });
            }
            else
            {
                var entity = _menuDal.Get <MPConfig>(id);
                if (entity != null)
                {
                    entity.ConfigValue = Newtonsoft.Json.JsonConvert.SerializeObject(config);
                    _menuDal.Update(entity);
                }
            }

            return(Json(AjaxResult.Success()));
        }
Esempio n. 24
0
        /// <summary>
        /// cập nhật ngày thu cho HoaDon với ID đã cho
        /// </summary>
        public AjaxResult CapNhatNgayThu(int hoaDonID, string ngayThu)
        {
            var    hoaDon     = hoaDonRepository.GetByID(hoaDonID);
            string bakNgayNop = null;

            if (hoaDon != null && hoaDon.Trangthaithu == true)
            {
                IGiaoDichRepository giaoDichRepository = uow.Repository <GiaoDichRepository>();
                var giaoDich = giaoDichRepository.GetGDThanhToanByHDID(hoaDonID);
                if (giaoDich == null)
                {
                    return(AjaxResult.Fail("Không tìm thấy giao dịch thanh toán cho hóa đơn đã chọn. Vui lòng tải lại trang.", true, new
                    {
                        HoaDon = new { NgayNopTien = bakNgayNop } // send back prev ngayNop
                    }));
                }

                bakNgayNop = hoaDon.NgayNopTien.Value.ToString("dd/MM/yyyy"); // backup ngayNop
                DateTime dt;
                if (DateTime.TryParseExact(ngayThu, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    if ((hoaDon.ThangHoaDon < dt.Month && hoaDon.NamHoaDon == dt.Year) || hoaDon.NamHoaDon < dt.Year)
                    {
                        hoaDon.NgayNopTien    = dt;
                        giaoDich.NgayGiaoDich = dt;
                        uow.SubmitChanges();
                        return(AjaxResult.Success("Ngày thu đã được cập nhật."));
                    }
                }
            }

            return(AjaxResult.Fail("Ngày thu không đúng hoặc hóa đơn chưa thanh toán.", false, new
            {
                HoaDon = new { NgayNopTien = bakNgayNop } // send back prev ngayNop
            }));
        }