public void Edit(CustomerViewModels client)
        {
            Customer customer = Repository.GetById(client.Id);

            Mapper.ModelToData(customer, client);
            Repository.Save();
        }
Example #2
0
        public Customer ModelToData(Customer customer, CustomerViewModels model)
        {
            customer.Name = model.Name;
            customer.Code = model.Code;

            return(customer);
        }
Example #3
0
        //searching
        public List <CustomerViewModels> SearchBy(string nama, string city, string email)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                var list = db.Customer.ToList();
                List <CustomerViewModels> listVM = new List <CustomerViewModels>();

                foreach (var item in list)
                {
                    if (item.Email == null)
                    {
                        item.Email = " ";
                    }
                    if (((item.FirstName.ToLower() + " " + item.LastName.ToLower()).Contains(nama.ToLower()) || string.IsNullOrEmpty(nama) || string.IsNullOrWhiteSpace(nama)) &&
                        (item.City.ToLower().Contains(city.ToLower()) || item.Country.ToLower().Contains(city.ToLower()) || string.IsNullOrEmpty(city) || string.IsNullOrWhiteSpace(city)) &&
                        (item.Email.ToLower().Contains(email.ToLower()) || string.IsNullOrEmpty(email) || string.IsNullOrWhiteSpace(email)))
                    {
                        CustomerViewModels viewModel = new CustomerViewModels();
                        viewModel.Id        = item.Id;
                        viewModel.FirstName = item.FirstName;
                        viewModel.LastName  = item.LastName;
                        viewModel.City      = item.City;
                        viewModel.Country   = item.Country;
                        viewModel.Phone     = item.Phone;
                        viewModel.Email     = item.Email;
                        listVM.Add(viewModel);
                    }
                }

                return(listVM);
            }
        }
Example #4
0
        public ActionResult Edit(CustomerViewModels customer)
        {
            if (ModelState.IsValid)
            {
                //API Akses
                string json        = JsonConvert.SerializeObject(customer);
                var    buffer      = System.Text.Encoding.UTF8.GetBytes(json);
                var    byteContent = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                string              ApiEndPoint = ApiUrl + "api/CustomerApi/";
                HttpClient          client      = new HttpClient();
                HttpResponseMessage response    = client.PutAsync(ApiEndPoint, byteContent).Result;

                string result  = response.Content.ReadAsStringAsync().Result.ToString();
                int    success = int.Parse(result);

                if (success == 1)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(customer));
                }
            }
            return(View(customer));
        }
Example #5
0
        public MainWindowViewModel()
        {
            // Add available pages
            PageViewModels.Add(new WelcomeViewModel());
            PageViewModels.Add(new HomeViewModel());
            PageViewModels.Add(new UserLoginViewModel());
            PageViewModels.Add(new WorkerLoginViewModel());
            PageViewModels.Add(new ProductsViewModel());
            PageViewModels.Add(new UserOrderViewModel());

            ShownViewModels.Add(new WelcomeViewModel());
            CustomerViewModels.Add(new UserOrderViewModel());

            // Set starting page
            CurrentPageViewModel = PageViewModels[0];

            Messenger.Default.Register <ChangePageHelper>
            (
                this,
                (action) => ChangeViewModel(action.PageName)
            );
            //Messenger.Default.Register<ChangePanelHelper>
            //(
            //    this,
            //    (action) => ChangePanelViewModel(action.panelType)
            //);
        }
Example #6
0
        public ActionResult Create(CustomerViewModels customer)
        {
            if (ModelState.IsValid)
            {
                //panggil api untuk cek nama
                // Check Nama API Akses http://localhost:2099/api/CustomerApi/CekNamaExisting?param=Maria&param2=Anders
                string              ApiEndPoint1 = ApiUrl + "api/CustomerApi/cekNama/" + customer.FirstName + "/" + customer.LastName;
                HttpClient          client1      = new HttpClient();
                HttpResponseMessage response1    = client1.GetAsync(ApiEndPoint1).Result;
                bool nama = bool.Parse(response1.Content.ReadAsStringAsync().Result.ToString());

                //panggil api untuk cek email
                string              ApiEndPoint2 = ApiUrl + "api/CustomerApi/cekEmail/" + customer.Email;
                HttpClient          client2      = new HttpClient();
                HttpResponseMessage response2    = client2.GetAsync(ApiEndPoint2).Result;
                bool email = bool.Parse(response2.Content.ReadAsStringAsync().Result.ToString());

                if (nama && email)
                {
                    ModelState.AddModelError("", "Maaf nama sudah ada di database");
                    ModelState.AddModelError("", "Maaf email sudah ada di database");
                    return(View(customer));
                }
                else if (nama)
                {
                    ModelState.AddModelError("", "Maaf nama sudah ada di database");
                    return(View(customer));
                }
                else if (email)
                {
                    ModelState.AddModelError("", "Maaf email sudah ada di database");
                    return(View(customer));
                }
                else
                {
                    //API Akses
                    string json        = JsonConvert.SerializeObject(customer);
                    var    buffer      = System.Text.Encoding.UTF8.GetBytes(json);
                    var    byteContent = new ByteArrayContent(buffer);
                    byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                    string              ApiEndPoint = ApiUrl + "api/CustomerApi/Post/";
                    HttpClient          client      = new HttpClient();
                    HttpResponseMessage response    = client.PostAsync(ApiEndPoint, byteContent).Result;

                    string result  = response.Content.ReadAsStringAsync().Result.ToString();
                    int    success = int.Parse(result);

                    if (success == 1)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(View(customer));
                    }
                }
            }
            return(View(customer));
        }
        public void Add(CustomerViewModels client)
        {
            Customer customer = new Customer();

            customer.Customer_ID = Guid.NewGuid();

            Repository.Add(Mapper.ModelToData(customer, client));

            Repository.Save();
        }
Example #8
0
        public ActionResult Details(string id)
        {
            CustomerViewModels model = Service.GetById(id);

            if (model == null)
            {
                return(new HttpStatusCodeResult(404));
            }

            return(View(Service.GetById(id)));
        }
Example #9
0
        public ActionResult Edit(string id)
        {
            CustomerViewModels model = Service.GetById(id);

            if (model == null)
            {
                return(new HttpStatusCodeResult(404));
            }

            return(View("Create", model));
        }
Example #10
0
        public ActionResult EditInfor(CustomerViewModels form)
        {
            customer           thisCustomer = (customer)Session["customer"];
            HttpPostedFileBase file         = form.ImagePath;

            if (file != null && file.ContentLength > 0)
            {
                string extend   = Path.GetExtension(file.FileName);
                string fileName = Utility.ComputeSha256Hash((thisCustomer.customer_email)) + extend;
                string path     = Path.Combine(Server.MapPath(Utility.PATH_IMG_CUSTOMER), fileName);

                var customer = db
                               .customers
                               .SingleOrDefault
                               (
                    n => (n.customer_email == thisCustomer.customer_email)
                               );
                if (customer != null)
                {
                    customer.customer_dob     = form.Dob;
                    customer.customer_gender  = form.Gender;
                    customer.customer_phone   = form.Phone;
                    customer.last_update      = DateTime.Now;
                    customer.customer_address = form.Address;

                    db.SubmitChanges();

                    customer_img customer_Img = db.customer_imgs.SingleOrDefault(x => x.customer_id.Equals(thisCustomer.customer_id));
                    if (customer_Img == null)
                    {
                        customer_Img = new customer_img();
                    }

                    customer_Img.customer_id       = thisCustomer.customer_id;
                    customer_Img.customer_img_path = Utility.CorrectPath(path);

                    file.SaveAs(path);
                    db.ExecuteQuery <customer_img>("insert into customer_img values ({0}, {1})", customer_Img.customer_id, customer_Img.customer_img_path);
                    //db.customer_imgs.InsertOnSubmit(customer_Img);
                    try
                    {
                        db.SubmitChanges();
                    }
                    catch (Exception e)
                    {
                    }

                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View());
            //return RedirectToAction("Index", "Home");
        }
Example #11
0
 public int put(CustomerViewModels customer)
 {
     try
     {
         service.UpdateCustomer(customer);
         return(1);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
Example #12
0
 public int post(CustomerViewModels customer)
 {
     try
     {
         service.AddNewCustomer(customer);
         return(1);
     }
     catch (Exception ex)
     {
         return(0);
     }
 }
 public ActionResult Search(CustomerViewModels model)
 {
     try
     {
         var data = _factory.GetListCustomer();
         model.ListCus = data;
     }
     catch (Exception e)
     {
         NSLog.Logger.Error("GetListCustomer: ", e);
         return(new HttpStatusCodeResult(400, e.Message));
     }
     return(PartialView("_ListData", model));
 }
Example #14
0
 public ActionResult Index()
 {
     try
     {
         CustomerViewModels model = new CustomerViewModels();
         model.StoreID = CurrentUser.StoreId;
         return(View(model));
     }
     catch (Exception ex)
     {
         _logger.Error("Customer_Index: " + ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
Example #15
0
 //create customer
 public void AddNewCustomer(CustomerViewModels customer)
 {
     using (ShopDBEntities db = new ShopDBEntities())
     {
         Customer model = new Customer();
         model.FirstName = customer.FirstName;
         model.LastName  = customer.LastName;
         model.City      = customer.City;
         model.Country   = customer.Country;
         model.Phone     = customer.Phone;
         model.Email     = customer.Email;
         db.Customer.Add(model);
         db.SaveChanges();
     }
 }
        public ActionResult Details(int id)
        {
            var customer = customers.SingleOrDefault(c => c.Id == id);

            var viewModel = new CustomerViewModels()
            {
                Customer = customer
            };

            if (customer == null)
            {
                return(HttpNotFound());
            }

            return(View(viewModel));
        }
Example #17
0
        public ActionResult CreateForOrder(CustomerViewModels tempCustomer, [Bind(Include = "Customer_ID,Customer_First_Name,Customer_Last_Name,Contact_Number,Alternate_Contact_Number,Allergy_Desctiption,Email_Address")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                customer.Customer_First_Name      = tempCustomer.FirstName;
                customer.Customer_Last_Name       = tempCustomer.LastName;
                customer.Contact_Number           = tempCustomer.PrimarymNum;
                customer.Alternate_Contact_Number = tempCustomer.AlternativeNum;
                customer.Email_Address            = tempCustomer.EmailAddress;
                customer.Allergy_Desctiption      = tempCustomer.AllergyDesc;
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Create", "Orders"));
            }

            return(View(tempCustomer));
        }
Example #18
0
 public ActionResult Search(CustomerViewModels model)
 {
     try
     {
         var datas = _factory.GetListCustomer(model.StoreID, null, CurrentUser.ListOrganizationId);
         foreach (var item in datas)
         {
             item.ImageURL = string.IsNullOrEmpty(item.ImageURL) ? Commons.Image100_100 : item.ImageURL;
             if (!string.IsNullOrEmpty(item.IC) && item.IC.Length > 8)
             {
                 item.IC = "****" + item.IC.Substring(item.IC.Length - 4, 4);
             }
             else
             {
                 item.IC = "********";
             }
             if (!string.IsNullOrEmpty(item.Phone) && item.Phone.Length > 8)
             {
                 item.Phone = "****" + item.Phone.Substring(item.Phone.Length - 4, 4);
             }
             else
             {
                 item.Phone = "********";
             }
             if (!string.IsNullOrEmpty(item.Email) && item.Email.Length > 8)
             {
                 item.Email = item.Email.Substring(0, 4) + "****";
             }
             else
             {
                 item.Email = "********";
             }
             if (string.IsNullOrEmpty(item.Name))
             {
                 item.Name = item.Email;
             }
         }
         model.ListItem = datas;
     }
     catch (Exception e)
     {
         _logger.Error("Customer_Search: " + e);
         return(new HttpStatusCodeResult(400, e.Message));
     }
     return(PartialView("_ListData", model));
 }
Example #19
0
        //update costumer
        public void UpdateCustomer(CustomerViewModels customer)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                Customer model = new Customer();
                model.Id        = customer.Id;
                model.FirstName = customer.FirstName;
                model.LastName  = customer.LastName;
                model.City      = customer.City;
                model.Country   = customer.Country;
                model.Phone     = customer.Phone;
                model.Email     = customer.Email;

                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Example #20
0
        public async Task <IActionResult> Create(CustomerViewModels model)
        {
            if (ModelState.IsValid)
            {
                //step 1 : Upload/ Save customer image to Azure blob

                var           customerId    = Guid.NewGuid();
                StorageHelper storageHelper = new StorageHelper();
                storageHelper.ConnectionString = this.configuration.GetConnectionString("StorageConnection");

                //getting image path
                var tempFile = Path.GetTempFileName();
                using (var fs = new FileStream(tempFile, FileMode.Create, FileAccess.Write))
                {
                    await model.Image.CopyToAsync(fs);
                }

                var fileName  = Path.GetFileName(model.Image.FileName);
                var tempPath  = Path.GetDirectoryName(tempFile);
                var imagePath = Path.Combine(tempPath, string.Concat(customerId, "_", fileName));
                System.IO.File.Move(tempFile, imagePath);// rename temp file

                //Upload image
                var ImageUrl = await storageHelper.UploadCustomerImageAsync("images", imagePath);

                //Step 2: Save Customer data to Azure table

                Customer customer = new Customer(customerId.ToString(), model.InsuranceType);
                customer.Fullname = model.FullName;
                customer.Email    = model.Email;
                customer.Amount   = model.Amount;
                customer.AppDate  = model.AppDate;
                customer.EndDate  = model.EndDate;
                customer.Premium  = model.Premium;
                customer.ImageURL = ImageUrl;
                await storageHelper.InsertCustomerAsync("Customers", customer);


                //Step 3: Add a confirmation message to Azure Queue
            }
            else
            {
            }
            return(View());
        }
        // GET: Customer
        public ActionResult Index()
        {
            var customerList = new List <Customer>
            {
                new Customer {
                    Id = 1, Name = "Andes"
                },
                new Customer {
                    Id = 2, Name = "Mary"
                }
            };
            var viewModel = new CustomerViewModels
            {
                CustomerList = customerList
            };

            return(View(viewModel));
        }
Example #22
0
        //select * from customer where id = "id"
        public CustomerViewModels GetCustomerById(int id)
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                Customer customer = db.Customer.Find(id);

                CustomerViewModels CustVM = new CustomerViewModels();
                CustVM.Id        = customer.Id;
                CustVM.FirstName = customer.FirstName;
                CustVM.LastName  = customer.LastName;
                CustVM.City      = customer.City;
                CustVM.Country   = customer.Country;
                CustVM.Phone     = customer.Phone;
                CustVM.Email     = customer.Email;

                return(CustVM);
            }
        }
Example #23
0
        public ActionResult CreateEdit(CustomerViewModels model)
        {
            if (ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(model.Id))
                {
                    Service.Add(model);
                }
                else
                {
                    Service.Edit(model);
                }

                return(RedirectToAction("Index"));
            }

            return(View("Create", model));
        }
Example #24
0
        // GET: Movies
        public ActionResult Index()
        {
            var moviesList = new List <Movie>
            {
                new Movie {
                    Id = 1, Name = "Shrek"
                },
                new Movie {
                    Id = 2, Name = "Wall-E"
                }
            };

            var viewModel = new CustomerViewModels
            {
                Movies = moviesList
            };

            return(View(viewModel));
        }
Example #25
0
        public List <CustomerViewModels> GetCustomerName()
        {
            using (ShopDBEntities db = new ShopDBEntities())
            {
                var list = db.Customer.ToList();
                List <CustomerViewModels> listVM = new List <CustomerViewModels>();

                foreach (var item in list)
                {
                    CustomerViewModels viewModel = new CustomerViewModels();
                    viewModel.Id        = item.Id;
                    viewModel.FirstName = item.FirstName;
                    viewModel.LastName  = item.LastName;
                    viewModel.City      = item.City;
                    viewModel.Country   = item.Country;
                    viewModel.Phone     = item.Phone;
                    viewModel.Email     = item.Email;
                    viewModel.FullName  = item.FirstName + " " + item.LastName;
                    listVM.Add(viewModel);
                }
                return(listVM);
            }
        }
Example #26
0
        // GET: Customers/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            int idx = id ?? 0;

            //API Akses
            string              ApiEndPoint = ApiUrl + "api/CustomerApi/Get/" + idx;
            HttpClient          client      = new HttpClient();
            HttpResponseMessage response    = client.GetAsync(ApiEndPoint).Result;

            string             result = response.Content.ReadAsStringAsync().Result.ToString();
            CustomerViewModels custVM = JsonConvert.DeserializeObject <CustomerViewModels>(result);

            //CustomerViewModels custVM = service.GetCustomerById(idx);

            if (custVM == null)
            {
                return(HttpNotFound());
            }
            return(View(custVM));
        }
        public ActionResult Index()
        {
            CustomerViewModels model = new CustomerViewModels();

            return(View(model));
        }