public ActionResult Update(string key, string json) { var msg = new JsonMessage(false, "Cập nhật dữ liệu thành công."); try { if (key != Keyapi) { return(Json(0, JsonRequestBehavior.AllowGet)); } var model = _da.GetById(ItemId); var birth = Request["Birthday_"]; var serial = Request["CardSerial"]; var pin = Request["PinCard"]; var NoteCate = Request["NoteCate"]; var PassWord = Request["PassWord"]; model.Birthday = birth.StringToDecimal(); 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; } } var customerCare = model.Customer_Care.FirstOrDefault(); if (customerCare != null && !string.IsNullOrEmpty(NoteCate)) { customerCare.Note = HttpUtility.UrlDecode(NoteCate); } else if (!string.IsNullOrEmpty(NoteCate)) { customerCare = new Customer_Care { Note = HttpUtility.UrlDecode(NoteCate), AgencyId = Agencyid() }; model.Customer_Care.Add(customerCare); } if (!string.IsNullOrEmpty(PassWord)) { model.PassWord = FDIUtils.CreatePasswordHash(PassWord, model.PasswordSalt); } model.FullName = HttpUtility.UrlDecode(model.FullName); model.Address = HttpUtility.UrlDecode(model.Address); model.Phone = phone; _da.Save(); } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được cập nhật"; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
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)); }
public ActionResult UpdateCustomerCare(string key, string json, int agencyId) { var msg = new JsonMessage(false, "Sở thích cập nhật thành công."); try { if (key != Keyapi) { return(Json(0, JsonRequestBehavior.AllowGet)); } var model = _da.GetById(ItemId); var NoteCate = Request["NoteCate"]; var customerCare = model.Customer_Care.Where(v => v.AgencyId == agencyId).FirstOrDefault(); if (customerCare != null) { customerCare.Note = HttpUtility.UrlDecode(NoteCate); } else { customerCare = new Customer_Care { Note = HttpUtility.UrlDecode(NoteCate), AgencyId = Agencyid() }; model.Customer_Care.Add(customerCare); } _da.Save(); } catch (Exception ex) { msg.Erros = true; msg.Message = "Dữ liệu chưa được cập nhật"; Log2File.LogExceptionToFile(ex); } return(Json(msg, JsonRequestBehavior.AllowGet)); }
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)); }