public void Delete(CustomerArea ObjDelete) { var ObjToDelete = _context.CustomerAreas.SingleOrDefault(m => m.CompanyID == ObjDelete.CompanyID && m.CustomerAreaID == ObjDelete.CustomerAreaID); if (ObjToDelete != null) { _context.CustomerAreas.Remove(ObjToDelete); } }
protected override void Seed(DataContext context) { CustomerArea area = new CustomerArea { Key = new Guid(0x73646976, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71), Name = "Pasitic Asian" }; Customer cus = new Customer { Key = new Guid(0x48eba18e, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f), CustomerName = "John Doe", DateOfBirth = new DateTime(1990, 02, 08), Address = "25 Oasinton street, Singapre City, Singapore", Town = "Singapore", PostCode = "+56", OrderLevel = false }; cus = new Customer { Key = new Guid(0x48eba18a, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f), CustomerName = "John Papa", DateOfBirth = new DateTime(1990, 02, 08), Address = "25 Oasinton street, Singapre City, Singapore", Town = "Singapore", PostCode = "+56", OrderLevel = true }; area.Customers.Add(cus); cus = new Customer { Key = new Guid(0x48eba18b, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f), CustomerName = "John Smith", DateOfBirth = new DateTime(1990, 02, 08), Address = "25 Oasinton street, Singapre City, Singapore", Town = "Singapore", PostCode = "+56", OrderLevel = true }; area.Customers.Add(cus); cus = new Customer { Key = new Guid(0x48eba18c, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f), CustomerName = "Adam Smith", DateOfBirth = new DateTime(1990, 02, 08), Address = "25 Oasinton street, Singapre City, Singapore", Town = "Singapore", PostCode = "+56", OrderLevel = true }; area.Customers.Add(cus); context.CustomerAreas.Add(area); area = new CustomerArea { Key = new Guid(0x73646977, 0x0000, 0x0010, 0x80, 0x00, 0x00, 0xAA, 0x00, 0x38, 0x9B, 0x71), Name = "North America" }; cus = new Customer { Key = new Guid(0x48eba18d, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f), CustomerName = "John Doe", DateOfBirth = new DateTime(1990, 02, 08), Address = "25 Oasinton street, Singapre City, Singapore", Town = "Singapore", PostCode = "+56", OrderLevel = false }; cus = new Customer { Key = new Guid(0x48eba18f, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f), CustomerName = "John Papa", DateOfBirth = new DateTime(1990, 02, 08), Address = "25 Oasinton street, Singapre City, Singapore", Town = "Singapore", PostCode = "+56", OrderLevel = true }; area.Customers.Add(cus); cus = new Customer { Key = new Guid(0x48eba19a, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f), CustomerName = "John Smith", DateOfBirth = new DateTime(1990, 02, 08), Address = "25 Oasinton street, Singapre City, Singapore", Town = "Singapore", PostCode = "+56", OrderLevel = true }; area.Customers.Add(cus); cus = new Customer { Key = new Guid(0x48eba19b, 0xf8c9, 0x4687, 0xbf, 0x11, 0x0a, 0x74, 0xc9, 0xf9, 0x6a, 0x8f), CustomerName = "Adam Smith", DateOfBirth = new DateTime(1990, 02, 08), Address = "25 Oasinton street, Singapre City, Singapore", Town = "Singapore", PostCode = "+56", OrderLevel = true }; area.Customers.Add(cus); context.CustomerAreas.Add(area); base.Seed(context); }
public Customer(string name, CustomerType type, CustomerArea area, string address, string tell, string workPlace, string remarkInfo, DateTime createTime) { Name = name; Type = type; Area = area; Address = address; Tell = tell; WorkPlace = workPlace; RemarksInfo = remarkInfo; CreateTime = createTime; }
public void Update(CustomerArea ObjUpdate) { var ObjToUpdate = _context.CustomerAreas.FirstOrDefault(m => m.CompanyID == ObjUpdate.CompanyID && m.CustomerAreaID == ObjUpdate.CustomerAreaID); if (ObjToUpdate != null) { ObjToUpdate.ArabicName = ObjUpdate.ArabicName; ObjToUpdate.EnglishName = ObjUpdate.EnglishName; ObjToUpdate.CustomerCityID = ObjUpdate.CustomerCityID; ObjToUpdate.InsDateTime = ObjUpdate.InsDateTime; ObjToUpdate.InsUserID = ObjUpdate.InsUserID; } }
public JsonResult SaveCustomerArea(CustomerAreaVM ObjToSave) { MsgUnit Msg = new MsgUnit(); try { var userId = User.Identity.GetUserId(); var UserInfo = _unitOfWork.User.GetMyInfo(userId); var CustomerAreaObj = new CustomerArea(); CustomerAreaObj.InsDateTime = DateTime.Now; CustomerAreaObj.InsUserID = userId; CustomerAreaObj.CompanyID = UserInfo.fCompanyId; CustomerAreaObj.CustomerAreaID = ObjToSave.CustomerAreaID; CustomerAreaObj.CustomerCityID = ObjToSave.CustomerCityID; if (String.IsNullOrEmpty(ObjToSave.EnglishName)) { ObjToSave.EnglishName = ObjToSave.ArabicName; } CustomerAreaObj.ArabicName = ObjToSave.ArabicName; CustomerAreaObj.EnglishName = ObjToSave.EnglishName; if (!ModelState.IsValid) { string Err = " "; var errors = ModelState.Values.SelectMany(v => v.Errors); foreach (ModelError error in errors) { Err = Err + error.ErrorMessage + " * "; } Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + Err; Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } _unitOfWork.CustomerArea.Add(CustomerAreaObj); _unitOfWork.Complete(); Msg.LastID = _unitOfWork.CustomerArea.GetMaxSerial(UserInfo.fCompanyId).ToString(); Msg.Code = 1; Msg.Msg = Resources.Resource.AddedSuccessfully; return(Json(Msg, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } }
public async Task <IActionResult> GetCustomerAreaById(Int64 CustomerAreaId) { CustomerArea Items = new CustomerArea(); try { Items = await _context.CustomerArea.Include(q => q.CustomerAreaProduct).Where(q => q.CustomerAreaId == CustomerAreaId).FirstOrDefaultAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(Ok(Items)); }
public JsonResult DeleteCustomerArea(CustomerAreaVM ObjDelete) { MsgUnit Msg = new MsgUnit(); try { var userId = User.Identity.GetUserId(); var UserInfo = _unitOfWork.User.GetMyInfo(userId); ObjDelete.CompanyID = UserInfo.fCompanyId; var CustomerAreaObj = new CustomerArea(); CustomerAreaObj.CompanyID = UserInfo.fCompanyId; CustomerAreaObj.CustomerAreaID = ObjDelete.CustomerAreaID; if (!ModelState.IsValid) { string Err = " "; var errors = ModelState.Values.SelectMany(v => v.Errors); foreach (ModelError error in errors) { Err = Err + error.ErrorMessage + " * "; } Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + Err; Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } _unitOfWork.CustomerArea.Delete(CustomerAreaObj); _unitOfWork.Complete(); Msg.Code = 1; Msg.Msg = Resources.Resource.DeletedSuccessfully; return(Json(Msg, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { Msg.Msg = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString(); Msg.Code = 0; return(Json(Msg, JsonRequestBehavior.AllowGet)); } }
public async Task <IActionResult> Delete([FromBody] CustomerArea _CustomerArea) { CustomerArea _CustomerAreaq = new CustomerArea(); try { _CustomerAreaq = _context.CustomerArea .Where(x => x.CustomerAreaId == (Int64)_CustomerArea.CustomerAreaId) .FirstOrDefault(); _context.CustomerArea.Remove(_CustomerAreaq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(Ok(_CustomerAreaq)); }
public async Task <ActionResult <CustomerArea> > Insert([FromBody] CustomerArea _CustomerArea) { CustomerArea _CustomerAreaq = new CustomerArea(); try { using (var transaction = _context.Database.BeginTransaction()) { try { _CustomerAreaq = _CustomerArea; _context.CustomerArea.Add(_CustomerAreaq); foreach (var item in _CustomerArea.CustomerAreaProduct) { item.CustomerAreaId = _CustomerArea.CustomerAreaId; item.ProductName = await _context.SubProduct.Where(q => q.SubproductId == item.ProductId).Select(q => q.ProductName).FirstOrDefaultAsync(); _context.CustomerAreaProduct.Add(item); } await _context.SaveChangesAsync(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(Ok(_CustomerAreaq)); }
public void UpdateCustomerAreas(ApplicationDbContext context, string[] selectedAreas, Customer customerToUpdate) { if (selectedAreas == null) { customerToUpdate.CustomerArea = new List <CustomerArea>(); return; } var selectedAreasHS = new HashSet <string>(selectedAreas); var customerAreas = new HashSet <int> (customerToUpdate.CustomerArea.Select(c => c.Area.AreaID)); foreach (var area in context.Area) { if (selectedAreasHS.Contains(area.AreaID.ToString())) { if (!customerAreas.Contains(area.AreaID)) { customerToUpdate.CustomerArea.Add( new CustomerArea { CustomerID = customerToUpdate.CustomerID, AreaID = area.AreaID }); } } else { if (customerAreas.Contains(area.AreaID)) { CustomerArea areaToRemove = customerToUpdate .CustomerArea .SingleOrDefault(c => c.AreaID == area.AreaID); context.Remove(areaToRemove); } } } }
public async Task <IActionResult> OnPostAsync(string[] selectedAreas) { if (!ModelState.IsValid) { return(Page()); } //Override values for created by and date Customer.CreatedDate = DateTime.Now; Customer.CreatedBy = Identity.GetUserId(User, _context); if (selectedAreas != null) { Customer.CustomerArea = new List <CustomerArea>(); foreach (var area in selectedAreas) { var areaToAdd = new CustomerArea { AreaID = int.Parse(area) }; Customer.CustomerArea.Add(areaToAdd); } } _context.Customer.Add(Customer); await _context.SaveChangesAsync(); await Audit.AddAuditRecord(_context, 'C', "Customer", "CustomerID", Customer.CustomerID, Identity.GetUserId(User, _context), "Customer Created"); //return RedirectToPage("./Index"); JObject jsonItem = JObject.FromObject(Customer); //objectID added for form.js jsonItem.Add("objectID", Customer.CustomerID); return(Content(jsonItem.ToString(), "application/json")); //return new JsonResult(Customer); }
public async Task <ActionResult <CustomerArea> > Update([FromBody] CustomerArea _CustomerArea) { CustomerArea _CustomerAreaq = _CustomerArea; try { _CustomerAreaq = await(from c in _context.CustomerArea .Where(q => q.CustomerAreaId == _CustomerArea.CustomerAreaId) select c ).FirstOrDefaultAsync(); _context.Entry(_CustomerAreaq).CurrentValues.SetValues((_CustomerArea)); //_context.CustomerArea.Update(_CustomerAreaq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(BadRequest($"Ocurrio un error:{ex.Message}")); } return(Ok(_CustomerAreaq)); }
public void Add(CustomerArea ObjSave) { _context.CustomerAreas.Add(ObjSave); }