Exemple #1
0
        public UserCustomerViewModel getCustomerUser(string exID)
        {
            UserCustomerViewModel customer = new UserCustomerViewModel();

            try
            {
                var Mcustomer = _dbContext.Customers.Where(s => exID.Equals(s.User.ExternalID.ToString())).FirstOrDefault();

                if (Mcustomer.Name != null)
                {
                    //// TODO: automapper mapping

                    var config = new MapperConfiguration(cfg => cfg.CreateMap <Models.Customer, UserCustomerViewModel>());

                    var mapper = new Mapper(config);
                    mapper.Map <Customer, UserCustomerViewModel>(Mcustomer, customer);
                }
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(customer);
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">Person Id</param>
        /// <returns></returns>
        public IActionResult EditCustomerUsers(Guid id)
        {
            var    customer     = PersonService.GetElementById(id);
            var    UserCustomer = uowUserCustomer.Entity.GetWithItems(u => u.IdCustomer == id, u => u.User).FirstOrDefault();
            string nameUser     = "";

            if (UserCustomer != null)
            {
                nameUser = uowUserCustomer.Entity.GetWithItems(u => u.IdCustomer == id, u => u.User).FirstOrDefault().User.UserName;
                // var idUser = uowUserCustomer.Entity.GetWithItems(u => u.IdCustomer == id, u => u.User).FirstOrDefault().IdUSer;
            }


            UserCustomerViewModel model = new UserCustomerViewModel();

            model.First_Name = customer.First_Name;
            model.Last_Name  = customer.Last_Name;
            model.Person_Id  = customer.Person_Id;
            model.Telephone  = customer.Phone;
            model.image      = customer.image;
            model.userName   = nameUser;



            return(View(model));
        }
Exemple #3
0
        //
        // GET: /Manage/ChangeProfile
        public async Task <ActionResult> ChangeProfile()
        {
            UserCustomerViewModel model =
                await ApiService <UserCustomerViewModel> .GetApi("/api/Customer/GetCurrentUserCustomer",
                                                                 User.Identity.Name);

            return(View(model));
        }
Exemple #4
0
        // Get user, then update its values so we don't get primary key conflicts when updating
        private ApplicationUser GetUpdatedUser(UserCustomerViewModel model)
        {
            ApplicationUser user = FindById(model.ApplicationUserId);

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;

            return(user);
        }
Exemple #5
0
        public HttpResponseMessage getCustomerUser(string exID)
        {
            UserCustomerViewModel result = _customerManager.getCustomerUser(exID);

            if (result != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, result));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }
        }
Exemple #6
0
        public void Delete(UserCustomerViewModel model)
        {
            Customer customer = _uow.CustomerRepository.FindById(model.Id);

            customer.Deleted = true;

            try {
                _uow.CustomerRepository.Update(customer);
                _uow.SaveChanges();
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace);
            }
        }
Exemple #7
0
        // GET: Customers/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserCustomerViewModel userCustomerViewModel = db.UserCustomerViewModels.Find(id);

            if (userCustomerViewModel == null)
            {
                return(HttpNotFound());
            }
            return(View(userCustomerViewModel));
        }
Exemple #8
0
        public async Task <ActionResult> Edit([Bind(Include = "Id, FirstName, LastName, CompanyName, City, Street, Postal, VatNumber, ApplicationUserId")]
                                              UserCustomerViewModel updatedUserCustomer)
        {
            string currentUserName = await ApiService <string> .GetApi("/api/Account/GetCurrentUserName", User.Identity.Name);

            if (ModelState.IsValid && currentUserName != updatedUserCustomer.Username)
            {
                await ApiService <UserCustomerViewModel> .PostApi($"/api/account/update", updatedUserCustomer, User.Identity.Name);

                return(RedirectToAction("Index"));
            }

            return(View(updatedUserCustomer));
        }
Exemple #9
0
        public async Task <ActionResult> DeleteConfirmed(UserCustomerViewModel model)
        {
            string currentUserName = await ApiService <string> .GetApi("/api/Account/GetCurrentUserName", User.Identity.Name);

            // The model that gets passed to the delete function only contains Id
            UserCustomerViewModel completeModel = await ApiService <UserCustomerViewModel> .GetApi($"/api/customer/get/{model.Id}", User.Identity.Name);

            if (currentUserName != completeModel.Username && !completeModel.Deleted)
            {
                await ApiService <UserCustomerViewModel> .PostApi($"/api/account/delete", model, User.Identity.Name);
            }

            return(RedirectToAction("Index"));
        }
Exemple #10
0
        private Customer GetUpdatedCustomer(UserCustomerViewModel model)
        {
            Customer customer = _uow.CustomerRepository.FindById(model.Id);

            customer.FirstName   = model.FirstName;
            customer.LastName    = model.LastName;
            customer.Deleted     = model.Deleted;
            customer.CompanyName = model.CompanyName;
            customer.City        = model.City;
            customer.Street      = model.Street;
            customer.Postal      = model.Postal;
            customer.VatNumber   = model.VatNumber;

            return(customer);
        }
Exemple #11
0
 public ActionResult Edit([Bind(Include = "Id,UserName,Email,Address,Phonenumber,Gender,Total_Quantity_Purchased,Total_Money_Purchased,Customer_Type,Status,Total_Purchased")] UserCustomerViewModel userCustomerViewModel)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userCustomerViewModel).State = EntityState.Modified;
         db.SaveChanges();
         TempData["message"] = "Edit";
         return(RedirectToAction("Index"));
     }
     else
     {
         TempData["message"] = "Fail";
     }
     return(View(userCustomerViewModel));
 }
Exemple #12
0
        // GET: Customers/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserCustomerViewModel userCustomerViewModel = db.UserCustomerViewModels.Find(id);

            if (userCustomerViewModel == null)
            {
                return(HttpNotFound());
            }
            db.UserCustomerViewModels.Remove(userCustomerViewModel);
            db.SaveChanges();
            TempData["message"] = "Delete";
            return(View(userCustomerViewModel));
        }
Exemple #13
0
 public ActionResult Create(UserCustomerViewModel userCustomerViewModel)
 {
     if (ModelState.IsValid)
     {
         var idnumber = db.UserCustomerViewModels.Count() + 1;
         userCustomerViewModel.Id        = "Customer" + idnumber;
         userCustomerViewModel.CreatedAt = DateTime.Now;
         userCustomerViewModel.Status    = UserCustomerViewModel.EnumStatus.Active;
         db.UserCustomerViewModels.Add(userCustomerViewModel);
         db.SaveChanges();
         TempData["message"] = "Create";
         return(RedirectToAction("Index"));
     }
     else
     {
         TempData["message"] = "Fail";
     }
     return(View(userCustomerViewModel));
 }
Exemple #14
0
        private UserCustomerViewModel FillUserCustomerViewModel(Customer customer)
        {
            UserCustomerViewModel model = new UserCustomerViewModel()
            {
                Id                = customer.Id,
                Username          = customer.ApplicationUser.UserName,
                FirstName         = customer.FirstName,
                LastName          = customer.LastName,
                Email             = customer.Email,
                CompanyName       = customer.CompanyName,
                City              = customer.City,
                Street            = customer.Street,
                Postal            = customer.Postal,
                VatNumber         = customer.VatNumber,
                EmailConfirmed    = customer.ApplicationUser.EmailConfirmed,
                ApplicationUserId = customer.ApplicationUser.Id
            };

            return(model);
        }
Exemple #15
0
        public bool Update(UserCustomerViewModel model)
        {
            ApplicationUser user = this.GetUpdatedUser(model);

            bool succeeded = _uow.AccountRepository.Update(user);

            if (succeeded)
            {
                try {
                    Customer customer = this.GetUpdatedCustomer(model);

                    _uow.CustomerRepository.Update(customer);
                    _uow.SaveChanges();
                    return(true);
                } catch (Exception ex) {
                    Console.WriteLine(ex.StackTrace);
                    return(false);
                }
            }

            return(false);
        }
Exemple #16
0
        public async Task <ActionResult> ChangeProfile(
            [Bind(Include = "Id, FirstName, LastName, CompanyName, City, Street, Postal, VatNumber, ApplicationUserId")]
            UserCustomerViewModel profile)
        {
            if (ModelState.IsValid)
            {
                string succeededJson =
                    await ApiService <UserCustomerViewModel> .PostApi($"/api/Account/Update", profile,
                                                                      User.Identity.Name);

                bool succeeded = JsonConvert.DeserializeObject <bool>(succeededJson);

                if (succeeded)
                {
                    TempData["StatusMessage"] = "Uw profiel is gewijzigd";
                    return(RedirectToAction("Index"));
                }
            }

            ModelState.AddModelError("", "Er is iets fout gegaan, gelieve de administrator te contacteren");
            return(View(profile));
        }
Exemple #17
0
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            UserCustomerViewModel model = await ApiService <UserCustomerViewModel> .GetApi($"/api/customer/get/{id}", User.Identity.Name);

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

            string currentUserName = await ApiService <string> .GetApi("/api/Account/GetCurrentUserName", User.Identity.Name);

            if (model.Deleted || model.Username == currentUserName)
            {
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemple #18
0
        public async Task <IActionResult> EditCustomerUsers(UserCustomerViewModel model)
        {
            var user = await userManager.FindByNameAsync(model.userName);

            var customer = PersonService.GetElementById(model.Person_Id);

            if (user == null)
            {
                ViewBag.ErrorMessage = $"User with Id = {model.userName} cannot be found";
                return(View("NotFound"));
            }
            //if (customer == null)
            //{
            //    ViewBag.ErrorMessage = $"User with Id = {model.Last_Name} {model.First_Name} cannot be found";
            //    return View("NotFound");
            //}
            uowUserCustomer.Entity.InsertElement(new UserCutomer()
            {
                User     = user,
                customer = customer
            });

            return(RedirectToAction("EditCustomerUsers", new { id = model.Person_Id }).WithSuccess("Affecter role", "Votre rôle affecter avec uccès"));
        }
 public bool Update([FromBody] UserCustomerViewModel model)
 {
     return(_accountBl.Update(model));
 }
 public void Delete([FromBody] UserCustomerViewModel model)
 {
     _accountBl.Delete(model);
 }