示例#1
0
        public ActionResult Add(string key, string json)
        {
            var model = new Base.Customer();
            var msg   = new JsonMessage(false, "Thêm mới dữ liệu thành công.");

            try
            {
                UpdateModel(model);
                var birth    = Request["Birthday_"];
                var parent   = Request["Parent"];
                var serial   = Request["CardSerial"];
                var pin      = Request["PinCard"];
                var NoteCate = Request["NoteCate"];
                if (!string.IsNullOrEmpty(serial))
                {
                    var carditem = _da.GetCardItem(serial, pin);
                    model.CardID = carditem.ID;
                }
                model.FullName     = HttpUtility.UrlDecode(model.FullName);
                model.Address      = HttpUtility.UrlDecode(model.Address);
                model.Birthday     = birth.StringToDecimal();
                model.DateCreated  = ConvertDate.TotalSeconds(DateTime.Now);
                model.IsDelete     = false;
                model.IsActive     = true;
                model.PasswordSalt = FDIUtils.CreateSaltKey(5);
                model.PassWord     = FDIUtils.CreatePasswordHash(model.PassWord ?? "fdi123456", model.PasswordSalt);
                if (!string.IsNullOrEmpty(NoteCate))
                {
                    var customerCare = new Customer_Care
                    {
                        Note     = HttpUtility.UrlDecode(NoteCate),
                        AgencyId = Agencyid()
                    };
                    model.Customer_Care.Add(customerCare);
                }
                _da.Add(model);
                _da.Save();
            }
            catch (Exception ex)
            {
                msg.Erros   = true;
                msg.Message = "Dữ liệu chưa được thêm mới";
                Log2File.LogExceptionToFile(ex);
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public ActionResult Actions()
        {
            var model = new Customer();
            var msg   = new JsonMessage(false, "Thêm mới dữ liệu thành công.");

            //List<Customer> ltsCustomerItems;
            //StringBuilder stbMessage;
            switch (DoAction)
            {
            case ActionType.Add:
                try
                {
                    UpdateModel(model);
                    var birth    = Request["Birthday_"];
                    var parent   = Request["Parent"];
                    var serial   = Request["CardSerial"];
                    var pin      = Request["PinCard"];
                    var NoteCate = Request["NoteCate"];

                    if (!string.IsNullOrEmpty(serial))
                    {
                        var carditem = _da.GetCardItem(serial, pin);
                        model.CardID = carditem.ID;
                    }
                    model.Birthday     = ConvertDate.TotalSeconds(ConvertUtil.ToDateTime(birth));
                    model.DateCreated  = ConvertDate.TotalSeconds(DateTime.Now);
                    model.IsDelete     = false;
                    model.IsActive     = true;
                    model.PasswordSalt = FDIUtils.CreateSaltKey(5);
                    model.PassWord     = FDIUtils.CreatePasswordHash(model.PassWord ?? "ssc123456", model.PasswordSalt);
                    if (!string.IsNullOrEmpty(NoteCate))
                    {
                        var customerCare = new Customer_Care
                        {
                            Note     = NoteCate,
                            AgencyId = AgencyId
                        };
                        model.Customer_Care.Add(customerCare);
                    }
                    _da.Add(model);
                    _da.Save();
                }
                catch (Exception ex)
                {
                    msg.Erros   = true;
                    msg.Message = "Thêm mới thất bại.";
                }
                break;

            case ActionType.Edit:
                try
                {
                    model = _da.GetById(ArrId.FirstOrDefault());
                    var birth  = Request["Birthday_"];
                    var serial = Request["CardSerial"];
                    var pin    = Request["PinCard"];
                    model.Birthday = ConvertDate.TotalSeconds(ConvertUtil.ToDateTime(birth));
                    var phone = model.Phone;
                    UpdateModel(model);
                    if (!model.CardID.HasValue && !string.IsNullOrEmpty(serial))
                    {
                        var carditem = _da.GetCardItem(serial, pin);
                        if (carditem != null)
                        {
                            model.CardID = carditem.ID;
                        }
                    }
                    if (!string.IsNullOrEmpty(model.PassWord))
                    {
                        model.PassWord = FDIUtils.CreatePasswordHash(model.PassWord, model.PasswordSalt);
                    }
                    model.Phone = phone;
                    _da.Save();
                    msg.Message = "Cập nhật dữ liệu thành công";
                }
                catch (Exception ex)
                {
                    msg.Erros   = true;
                    msg.Message = "Dữ liệu chưa được cập nhật";
                    Log2File.LogExceptionToFile(ex);
                }
                break;

            case ActionType.Delete:
                try
                {
                    var lst = _da.GetListByArrId(ArrId);
                    foreach (var item in lst)
                    {
                        item.IsDelete = true;
                    }
                    _da.Save();
                    msg.Message = "Xóa dữ liệu thành công";
                }
                catch (Exception ex)
                {
                    msg.Erros   = true;
                    msg.Message = "Dữ liệu chưa được xóa";
                    Log2File.LogExceptionToFile(ex);
                }
                break;

            default:
                msg.Message = "Không có hành động nào được thực hiện.";
                msg.Erros   = true;
                break;
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }