public PartialViewResult Edit(string id)
        {
            CustomerModels model = GetDetail(id);

            model.ConfirmPassword = model.Password;
            return(PartialView("_Edit", model));
        }
 public ActionResult Create(CustomerModels model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("Create", model));
         }
         string msg = "", cusId = "";
         model.CreatedUser = CurrentUser.UserId;
         model.Password    = CommonHelper.Encrypt(model.Password);
         var result = _factory.InsertCustomer(model, ref msg, ref cusId);
         if (result)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("Email", msg);
             model.Password      = CommonHelper.Decrypt(model.Password);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("Create", model));
         }
     }
     catch (Exception ex)
     {
         NSLog.Logger.Error("CustomerCreate: ", ex);
         ModelState.AddModelError("Email", "Có một lỗi xảy ra!");
         model.Password      = CommonHelper.Decrypt(model.Password);
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("Create", model));
     }
 }
Beispiel #3
0
        public IHttpActionResult InsertCustomer(CustomerModels customer)
        {
            InventoryClass obj = new InventoryClass();

            obj.InsertCustomer(customer);
            return(Created(new Uri(Request.RequestUri + ""), "Customer created"));
        }
        public IActionResult Register(CustomerModels newCustomer)
        {//works only if no customer validation lol
            try
            {
                CustomerModels customer = new CustomerModels()
                {
                    Username = newCustomer.Username,
                    email    = newCustomer.email
                };

                /* List<CustomerModels> getCustomersTask = _customerService.GetAllCustomers();
                 * foreach (var h in getCustomersTask)
                 * {
                 *   if (newCustomer.Username.Equals(h.Username))
                 *   {
                 *       throw new Exception("Sorry this username is already taken");
                 *   }
                 *   else
                 *   {
                 *       if (newCustomer.email.Equals(h.email))
                 *       {
                 *           throw new Exception("Sorry this email is already registered");
                 *       }
                 *   }
                 * } */
                _customerService.AddCustomer(newCustomer);
                CartsModel cart = new CartsModel();
                cart.CustomerID = newCustomer.ID;
                return(Ok());
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Beispiel #5
0
        public bool UpdateCustomer(CustomerModels customer)
        {
            try
            {
                CustomerModels oldCustomer = _entity.Customers.Find(customer.Id);

                oldCustomer.FirstName   = customer.FirstName;
                oldCustomer.MiddleName  = customer.MiddleName;
                oldCustomer.LastName    = customer.LastName;
                oldCustomer.Phone       = customer.Phone;
                oldCustomer.Email       = customer.Email;
                oldCustomer.Modify_Date = DateTime.UtcNow;
                oldCustomer.State       = customer.State;
                oldCustomer.Country     = customer.Country;
                oldCustomer.City        = customer.City;
                oldCustomer.Address1    = customer.Address1;
                oldCustomer.Address2    = customer.Address2;
                oldCustomer.Facebook    = customer.Facebook;
                oldCustomer.Instagram   = customer.Instagram;
                oldCustomer.Remarks     = customer.Remarks;

                _entity.Entry(oldCustomer).State = EntityState.Modified;
                _entity.SaveChanges();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #6
0
        public CustomerModels GetCustmerName(string CustomerID)
        {
            InventoryClass obj     = new InventoryClass();
            CustomerModels custmer = new CustomerModels();
            string         sql     = "";

            sql = "select Ledger_Name,city,Ledger_ID from Ledger_Master l,Employee e where l.ledger_name=e.Emp_name and Ledger_ID='" + CustomerID + "'";
            var SqlDtr = obj.GetRecordSet(sql);

            if (SqlDtr.Read())
            {
                custmer.CustomerName = SqlDtr.GetValue(0).ToString() + ":" + SqlDtr.GetValue(2).ToString();
                if (SqlDtr.GetValue(1).ToString().Equals(""))
                {
                    custmer.City = "";
                }
                else
                {
                    custmer.City = SqlDtr.GetValue(1).ToString();
                }
                custmer.Flag = 1;
            }
            SqlDtr.Close();
            return(custmer);
        }
        public string Update(CustomerModels customerModels)
        {
            var User = (from s in oSaleforceConnector.Customers where s.Email == customerModels.Email select s).FirstOrDefault();

            try
            {
                if (ModelState.IsValid)
                {
                    if (CheckUser(oCustomermodels.Email) == false)
                    {
                        var keyNew   = Helper.GeneratePassword(10);
                        var password = Helper.Encrypt(customerModels.Password, keyNew);
                        customerModels.SaltKey  = keyNew;
                        customerModels.Password = password;
                        var result = ocustomerBL.CustomerEdit(customerModels);
                        return("2");
                    }
                    else
                    {
                        return("-1");
                    }
                }
                return("3");
            }
            catch (Exception ex)
            {
                long CustomerID = Convert.ToInt32(User.Id);
                ex.Message.ToString();
                Errorlog.ErrorDetail(CustomerID, orderId, "User Updated", ex.Message, 1);
                return("0");
            }
        }
Beispiel #8
0
        public ActionResult AccountDetails()
        {
            var            FoundUserId = User.Identity.GetUserId();
            CustomerModels customer    = db.CustomerModels.Where(c => c.ApplicationUserId == FoundUserId).FirstOrDefault();

            return(View(customer));
        }
Beispiel #9
0
        public ActionResult Register(CustomerModels cm)
        {
            CustomerModels c = new CustomerModels();

            if (!ModelState.IsValid)
            {
                ViewBag.IsSuccess = false;
                ViewBag.Message   = "Customer Register Failed.";

                return(View("Index", c));
            }

            cm.AspNetUsersId = User.Identity.Name;
            _context.CustomerModels.Add(cm);

            try
            {
                _context.SaveChanges();

                ViewBag.IsSuccess = true;
                ViewBag.Message   = "Customer registered successfully. Thanks for using our service";
                ModelState.Clear();
            }
            catch (Exception ex)
            {
                ViewBag.IsSuccess = false;
                ViewBag.Message   = "Error in adding Customer! \nError: " + ex.Message;
            }

            return(View("Index", c));
        }
Beispiel #10
0
        public ActionResult Save(CustomerModels customer)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CustomerFormViewModel
                {
                    Customer        = customer,
                    MembershipTypes = _context.MembershipTypes.ToList()
                };

                return(View("CustomerForm", viewModel));
            }

            if (customer.Id == 0)
            {
                _context.Customers.Add(customer);
            }
            else
            {
                var customerInDb = _context.Customers.Single(a => a.Id == customer.Id);

                customerInDb.Name             = customer.Name;
                customerInDb.Birthdate        = customer.Birthdate;
                customerInDb.MembershipTypeId = customer.MembershipTypeId;
                customerInDb.IsSubscribed     = customer.IsSubscribed;
            }

            _context.SaveChanges();

            return(RedirectToAction("Index", "Customers"));
        }
 public ActionResult Delete(CustomerModels model)
 {
     try
     {
         ModelState.Clear();
         if (!ModelState.IsValid)
         {
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         var msg    = "";
         var result = _factory.Delete(model.ID, CurrentUser.UserId, ref msg);
         if (result)
         {
             return(RedirectToAction("Index"));
         }
         ModelState.AddModelError("ErrorMessage", msg);
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
     catch (Exception ex)
     {
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
 // GET: Customer/Delete/5
 public ActionResult Delete(int id)
 {
     using (CustomerModels cmd = new CustomerModels())
     {
         return(View(cmd.customerdetails.Where(x => x.id == id).FirstOrDefault()));
     }
 }
 // GET: Customer/Edit/5
 public ActionResult Edit(int id)
 {
     using (CustomerModels ccs = new CustomerModels())
     {
         return(View(ccs.customerdetails.Where(x => x.id == id).FirstOrDefault()));
     }
 }
 // GET: Customer
 public ActionResult Index()
 {
     using (CustomerModels cust = new CustomerModels())
     {
         return(View(cust.customerdetails.ToList()));
     }
 }
Beispiel #15
0
        public IHttpActionResult InsertorUpdateCustomerMapping(CustomerModels customer)
        {
            int x = 0;

            dbobj.Insert_or_Update("update Customer set ssr='" + customer.CustomerID + "' where Cust_Name='" + customer.CustomerName + "'", ref x);
            return(Created(new Uri(Request.RequestUri + ""), "Customer Mapping Updated"));
        }
        public ActionResult Edit(CustomerModels model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Edit", model));
                }

                string msg = "";
                model.UpdatedBy = CurrentUser.UserId;
                var result = _factory.InsertOrUpdateByAdminSite(model, ref msg);
                if (result)
                {
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("ErrorMessage", msg);
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Edit", model));
            }
            catch (Exception ex)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Edit", model));
            }
        }
Beispiel #17
0
        public bool UpdateCustomer(CustomerModels model, ref string msg)
        {
            bool result = true;

            using (DataContext cxt = new DataContext())
            {
                var _isExits = cxt.dbCustomer.Any(x => x.Email.Equals(model.Email) && x.IsActive && !x.ID.Equals(model.ID));
                if (_isExits)
                {
                    result = false;
                    msg    = "Địa chỉ email đã tồn tại";
                }
                else
                {
                    using (var transaction = cxt.Database.BeginTransaction())
                    {
                        try
                        {
                            var itemUpdate = cxt.dbCustomer.Where(x => x.ID == model.ID).FirstOrDefault();
                            if (itemUpdate != null)
                            {
                                itemUpdate.FirstName     = model.FirstName;
                                itemUpdate.LastName      = model.LastName;
                                itemUpdate.Name          = model.Name;
                                itemUpdate.Phone         = model.Phone;
                                itemUpdate.Password      = model.Password;
                                itemUpdate.Country       = model.Country;
                                itemUpdate.Address       = model.Address;
                                itemUpdate.Email         = model.Email;
                                itemUpdate.Gender        = model.Gender;
                                itemUpdate.BirthDate     = model.BirthDate;
                                itemUpdate.MaritalStatus = model.MaritalStatus;
                                itemUpdate.IsActive      = model.IsActive;
                                itemUpdate.ModifiedDate  = DateTime.Now;
                                itemUpdate.ModifiedUser  = model.CreatedUser;

                                cxt.SaveChanges();
                                transaction.Commit();
                            }
                        }
                        catch (Exception ex)
                        {
                            NSLog.Logger.Error("Không thể cập nhập cho khách hàng này. Làm ơn kiểm tra lại!", ex);
                            result = false;
                            msg    = "Không thể cập nhập cho khách hàng này. Làm ơn kiểm tra lại!";
                            transaction.Rollback();
                        }
                        finally
                        {
                            if (cxt != null)
                            {
                                cxt.Dispose();
                            }
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #18
0
        public ActionResult DeleteConfirmed(int id)
        {
            CustomerModels customerModels = db.Customers.Find(id);

            db.Customers.Remove(customerModels);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #19
0
        public double?ChargingACustomer(CustomerModels customer)
        {
            customer.bill = customer.bill += 5;

            var charge = customer.bill;

            return(charge);
        }
Beispiel #20
0
 /// <summary>
 /// customer section
 /// </summary>
 public Customer ParseCustomer(CustomerModels customer)
 {
     return(new Customer()
     {
         Username = customer.Username,
         Email = customer.email
     });
 }
        public IActionResult Index()
        {
            CustomerModels data = new CustomerModels
            {
                AllCustomers = _context.Customers.ToList(),
                Customer     = new Customer()
            };

            return(View(data));
        }
 public ActionResult Edit([Bind(Include = "ID,FirstName,LastName,Number,Street,City,State,Zip")] CustomerModels customerModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customerModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customerModels));
 }
Beispiel #23
0
 public ActionResult Edit([Bind(Include = "CustomersId,UserId,Username,FirstName,LastName,Email,Address,ZipCode,AmountDue,PickupDate")] CustomerModels customerModels)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customerModels).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(customerModels));
 }
Beispiel #24
0
        public IHttpActionResult GetCustomersData(CustomerModels customer)
        {
            InventoryClass obj = new InventoryClass();
            DataSet        ds;

            ds = obj.ShowCustomerInfo(customer.CustomerID, customer.CustomerName, customer.Place);
            DataTable dt = ds.Tables[0];
            DataView  dv = new DataView(dt);

            return(Ok(dv));
        }
        public ActionResult Create([Bind(Include = "UserId,FirstName,LastName,Number,Street,City,State,Zip")] CustomerModels customerModels)
        {
            if (ModelState.IsValid)
            {
                customerModels.UserId = User.Identity.GetUserId();
                db.CustomerModels.Add(customerModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customerModels));
        }
 public IActionResult GetCustomerByID(int id)
 {
     try
     {
         CustomerModels customer = _customerService.GetCustomerByID(id);
         return(Ok(customer));
     }
     catch (Exception)
     {
         return(StatusCode(500));
     }
 }
        public ActionResult Create(CustomerModels model)
        {
            try
            {
                byte[] photoByte = null;
                if (!ModelState.IsValid)
                {
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(PartialView("_Create", model));
                }
                if (model.PictureUpload != null && model.PictureUpload.ContentLength > 0)
                {
                    Byte[] imgByte = new Byte[model.PictureUpload.ContentLength];
                    model.PictureUpload.InputStream.Read(imgByte, 0, model.PictureUpload.ContentLength);
                    model.PictureByte   = imgByte;
                    model.ImageURL      = Guid.NewGuid() + Path.GetExtension(model.PictureUpload.FileName);
                    model.PictureUpload = null;
                    photoByte           = imgByte;
                }

                var msg = "";
                var id  = "";
                model.CreatedBy = CurrentUser.Email;
                model.Password  = CommonHelper.Encrypt(model.Password);
                var result = _factory.CreateOrUpdate(model, ref id, ref msg);
                if (result)
                {
                    if (!string.IsNullOrEmpty(model.ImageURL) && model.PictureByte != null)
                    {
                        var          path = Server.MapPath("~/Uploads/Employees/" + model.ImageURL);
                        MemoryStream ms   = new MemoryStream(photoByte, 0, photoByte.Length);
                        ms.Write(photoByte, 0, photoByte.Length);
                        System.Drawing.Image imageTmp = System.Drawing.Image.FromStream(ms, true);

                        ImageHelper.Me.SaveCroppedImage(imageTmp, path, model.ImageURL, ref photoByte);
                    }
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("FirstName", msg);
                model.Password        = CommonHelper.Decrypt(model.Password);
                model.ConfirmPassword = model.Password;
                Response.StatusCode   = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Create", model));
            }
            catch (Exception ex)
            {
                model.Password        = CommonHelper.Decrypt(model.Password);
                model.ConfirmPassword = model.Password;
                Response.StatusCode   = (int)HttpStatusCode.BadRequest;
                return(PartialView("_Create", model));
            }
        }
Beispiel #28
0
        public ActionResult Create([Bind(Include = "CustomersId,UserId,Username,FirstName,LastName,Email,Address,ZipCode,AmountDue,PickupDate")] CustomerModels customerModels)
        {
            if (ModelState.IsValid)
            {
                customerModels.ApplicationUserId = User.Identity.GetUserId();
                db.Customers.Add(customerModels);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customerModels));
        }
 public IActionResult GetAllOrdersByCustomerID(int id)
 {
     try
     {
         CustomerModels    customer = _customerService.GetCustomerByID(id);
         List <OrderModel> orders   = _customerService.GetAllOrdersByCustomerID(customer.ID);
         return(Ok(orders));
     }
     catch (Exception)
     {
         return(StatusCode(500));
     }
 }
Beispiel #30
0
 public IActionResult SignInCustomer(CustomerModels customer)
 {
     try
     {
         CustomerModels signInCustomer = customerService1.GetCustomerByName(customer.Username);
         string         userName       = signInCustomer.Username;
         return(Ok(signInCustomer));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }