public CustomerProfileModel CustomerProfile(int CustId) { using (var db = new EntityContext()) { TbCustomer customer = customerUtility.GetCustomerById(db, CustId); CustomerSingleModel customerModelSource = customerUtility.CustomerSingleModelProperty(customer); List <TbItems> items = db.TbItems .Include(i => i.Customer) .Include(i => i.Status) .Where(i => i.Customer.Id == CustId).ToList(); List <ItemSingleModel> itemsModelSource = new List <ItemSingleModel>(); if (items != null) { itemsModelSource = itemsUtility.AssingItemsProperty(items); } ; CustomerProfileModel profile = new CustomerProfileModel { customerModel = customerModelSource, itemsModel = itemsModelSource }; return(profile); } }
public bool Create(CustomerSingleModel model) { using (var db = new EntityContext()) { if (!CheckDuplicateNumber(model.Phonenumber)) { TbCustomer customer = new TbCustomer { Phonenumber = model.Phonenumber, Name = model.Name, Password = model.Password, Address = model.Address, BCEL_Baht = model.BCEL_Baht, BCEL_Dollar = model.BCEL_Dollar, BCEL_Kip = model.BCEL_Kip, Status = db.tbStatuses.FirstOrDefault(s => s.Id == 1), isDeleted = false }; db.tbCustomers.Add(customer); db.SaveChanges(); return(true); } else { return(false); } } }
public ActionResult CRegister(CustomerSingleModel model) { if (ModelState.IsValid) { bool duplicateCheck = _custService.CheckDuplicateNumber(model.Phonenumber); if (duplicateCheck == true) { ViewBag.DuplicateMessage = "ເບີດັ່ງກ່າວໄດ້ຖືກໄຊ້ແລ້ວ"; return(View("CRegister", model)); } else { bool result = _custService.Create(model); if (result == true) { ViewBag.Message = "ລົງທະບຽນສຳເລັດ"; return(View("CRegister")); } else { ViewBag.Message = "ລົງທະບຽນບໍ່ສຳເລັດ ກະລຸນາກວດເບີ່ງຂໍ້ມູນຂອງທ່ານ"; return(View("CRegister", model)); } } } else { return(View()); } }
public CustomerSingleModel GetSingle(int id) { using (var db = new EntityContext()) { var customer = customerUtility.GetCustomerById(db, id); CustomerSingleModel model = customerUtility.CustomerSingleModelProperty(customer); return(model); } }
public ActionResult CUpdateProfile(CustomerSingleModel model) { if (Session["UserId"] == null) { return(RedirectToAction("CLogin", "Account")); } else { if (ModelState.IsValid) { int id = model.Id ?? default(int); bool checkDuplicate = _custService.CheckDuplicateNumber(id, model.Phonenumber); if (checkDuplicate == true) { ViewBag.Duplicate = "ເບີດັ່ງກ່າວໄດ້ຖືກນຳໃຊ້ແລ້ວ ກະລຸນາເລືອກເບີໃຫມ່"; return(View()); } else { bool result = _custService.Edit(model); if (result == true) { var postModel = _custService.GetSingle(id); ViewBag.Message = "ປ່ຽນແປງສຳເລັດ"; return(View(postModel)); } else { ViewBag.Message = "ປ່ຽນແປງບໍ່ສຳເລັດ"; return(View(model)); } } } else { return(View()); } } }
public bool Edit(CustomerSingleModel model) { using (var db = new EntityContext()) { int customerId = model.Id ?? default(int); if (CheckDuplicateNumber(customerId, model.Phonenumber)) { return(false); } ; var customer = customerUtility.GetCustomerById(db, customerId); db.Entry(customer).State = EntityState.Modified; customer.Address = model.Address; customer.Phonenumber = model.Phonenumber; customer.Password = model.Password; customer.BCEL_Baht = model.BCEL_Baht; customer.BCEL_Dollar = model.BCEL_Dollar; customer.BCEL_Kip = model.BCEL_Kip; db.SaveChanges(); return(true); } }