Exemple #1
0
        public JsonResult DeleteEvent(string id)
        {
            var result = new MessageReport(false, "Có lỗi xảy ra");

            if (!string.IsNullOrEmpty(id))
            {
                var obj = new tblActiveCard();

                var activecard = _tblActiveCardService.GetById(id);

                if (activecard != null)
                {
                    var subid = activecard.SubId;
                    var card  = _tblCardService.GetByCardNumber(activecard.CardNumber);
                    if (card != null)
                    {
                        if (Convert.ToDateTime(card.ExpireDate).Date == Convert.ToDateTime(activecard.NewExpireDate).Date)
                        {
                            card.ExpireDate = activecard.OldExpireDate;
                            _tblCardService.Update(card);
                            result = _tblActiveCardService.DeleteById(id);
                        }
                        else
                        {
                            result = new MessageReport(false, "Không thể xóa");
                        }

                        //xóa chi tiết gia hạn
                        if (result.isSuccess)
                        {
                            _tblActiveCardService.DeleteExtendBySubId(subid);
                        }
                    }
                }

                if (result.isSuccess)
                {
                    WriteLog.Write(result, GetCurrentUser.GetUser(), id, "", "tblActiveCard", ConstField.ParkingCode, ActionConfigO.Delete);
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Update(tblCardSubmit obj, HttpPostedFileBase FileUpload, string key, string cardgroups, string customergroups, string active, string fromdate, string todate, string isCheckByTime = "0", int page = 1)
        {
            var oldObj = _itblCardService.GetCustomById(Guid.Parse(obj.CardID));

            if (oldObj == null)
            {
                return(View(obj));
            }
            //valid card
            if ((string.IsNullOrWhiteSpace(obj.CardNo) || string.IsNullOrEmpty(obj.CardNo)) || string.IsNullOrEmpty(obj.CardGroupID))
            {
                if ((string.IsNullOrWhiteSpace(obj.CardNo) || string.IsNullOrEmpty(obj.CardNo)))
                {
                    ModelState.AddModelError("CardNo", "Please enter CardNo");
                }
                if (string.IsNullOrEmpty(obj.CardGroupID))
                {
                    ModelState.AddModelError("CardGroupID", "Please enter CardGroupId");
                }
                return(View(obj));
            }

            //if (FileUpload != null)
            //{
            //    var extension = Path.GetExtension(FileUpload.FileName);
            //    var fileName = Path.GetFileName(string.Format("{0}{1}", StringUtil.RemoveSpecialCharactersVn(FileUpload.FileName.Replace(extension, "")).GetNormalizeString(), extension));
            //    var url = ConfigurationManager.AppSettings["FileUploadAvatar"];

            //    oldObj.CustomerAvatar = string.Format("{0}{1}", url, fileName);
            //}
            //Gán giá trị
            var result = new MessageReport();
            var map    = _itblCardService.GetById(Guid.Parse(obj.CardID));

            if (map != null)
            {
                var existed = _itblCardService.GetByCardNumber_Id(map.CardNumber, Guid.Parse(obj.CardID));
                if (existed != null)
                {
                    ModelState.AddModelError("CardNumber", "mã thẻ đã tồn tại");
                    return(View(obj));
                }
                map.CardNumber = obj.CardNumber;
            }
            //thẻ
            map.CardNo        = obj.CardNo;
            map.CardGroupID   = obj.CardGroupID;
            map.Description   = !string.IsNullOrWhiteSpace(obj.CardDescription) ? obj.CardDescription : "";
            map.isAutoCapture = obj.IsAutoCapture;
            map.DVT           = obj.DVT;
            //ngày
            map.DateRegister = Convert.ToDateTime(obj.DtpDateRegisted);
            map.DateRelease  = Convert.ToDateTime(obj.DtpDateReleased);
            //khách hàng
            //obj.CustomerAvatar = oldObj.CustomerAvatar;
            map.CustomerID = GetOrSetCustomer(obj, FileUpload);
            result         = _itblCardService.Update(map);
            if (result.isSuccess)
            {
                return(RedirectToAction("Index", new { }));
            }
            else
            {
                ModelState.AddModelError("", result.Message);
                return(View(obj));
            }
        }