public async Task <ActionResult> AddAdress(CustomerAddressAppIG4Item data) { if (data.Latitude == null || data.Longitude == null) { return(Json(new JsonMessage(1000, "Tọa độ không được để trống"), JsonRequestBehavior.AllowGet)); } if (customerAddressDA.CheckExit(CustomerId, data.Latitude.Value, data.Longitude.Value)) { return(Json(new JsonMessage(1000, "Tọa độ đã tồn tại"), JsonRequestBehavior.AllowGet)); } if (data.IsDefault) { customerAddressDA.ResetDefault(CustomerId); } var cus = customerDA.GetById(CustomerId); var item = new CustomerAddress() { CustomerId = CustomerId, CustomerName = cus.FullName, Address = data.Address, DateCreated = DateTime.Now, IsDefault = data.IsDefault, Phone = cus.Mobile, Latitude = data.Latitude, Longitude = data.Longitude, City = data.City, District = data.District, Commune = data.Commune, IsDelete = false, AddressType = data.AddressType }; customerAddressDA.Add(item); await customerAddressDA.SaveAsync(); return(Json(new BaseResponse <CustomerAddressAppIG4Item>() { Code = 200, Data = customerAddressDA.GetItemById(item.ID) }, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> UpdateAddress(CustomerAddressAppIG4Item data) { if (data.Latitude == null || data.Longitude == null) { return(Json(new JsonMessage(1000, "Tọa độ không được để trống"), JsonRequestBehavior.AllowGet)); } var item = customerAddressDA.GetById(data.ID, CustomerId); if (item == null) { return(Json(new JsonMessage(1000, "Địa chỉ không tồn tại"), JsonRequestBehavior.AllowGet)); } if (customerAddressDA.CheckExit(data.ID, CustomerId, data.Latitude.Value, data.Longitude.Value)) { return(Json(new JsonMessage(1000, "Tọa độ đã tồn tại"), JsonRequestBehavior.AllowGet)); } if (data.IsDefault) { customerAddressDA.ResetDefault(CustomerId); } var cus = customerDA.GetById(CustomerId); item.Address = data.Address; item.Latitude = data.Latitude; item.Longitude = data.Longitude; item.City = data.City; item.District = data.District; item.Commune = data.Commune; item.IsDefault = data.IsDefault; item.AddressType = data.AddressType; await customerAddressDA.SaveAsync(); return(Json(new BaseResponse <CustomerAddressAppIG4Item>() { Code = 200, Data = data, Erros = false, Message = "" }, JsonRequestBehavior.AllowGet)); }