Пример #1
0
        public async Task <ActionResult> UsersDelete(int customerAuditorID, int customerID, string userId)
        {
            if ((userId == null) || (userId.ToString().Length == 0))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //var user = customerAuditorRepository.FindCustomerAuditorsByUserIDAsync(userId);
            //if (user == null)
            //{
            //    return HttpNotFound();
            //}

            //Falta eliminar la relacion del usuario con los Clientes
            //await customerAuditorRepository.DeleteByUserIdAsync(userId);

            var user = await userManager.FindByIdAsync(userId);

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

            var userAuditor = new CustomerAuditor()
            {
                CustomerAuditorID = customerAuditorID, CustomerID = customerID, User = (AdminUser)user, UserId = userId
            };

            var model = new EditCustomerAuditorUserViewModel(userAuditor);

            return(View(model));
        }
        public async Task <ActionResult> UsersEdit(int customerAuditorID)
        {
            //if (id == null)
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}
            CustomerAuditor customerAuditor = await customerAuditorRepository.FindByIdAsync(customerAuditorID);

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

            var model = new EditCustomerAuditorUserViewModel(customerAuditor);

            return(View(model));
        }
        public async Task <ActionResult> UsersDelete(int customerAuditorID)
        {
            //if ((customerAuditorID == null) || (username.ToString().Length == 0))
            //{
            //    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            //}

            CustomerAuditor customerAuditor = await customerAuditorRepository.FindByIdAsync(customerAuditorID);

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

            var model = new EditCustomerAuditorUserViewModel(customerAuditor);

            return(View(model));
        }
        public async Task <ActionResult> UsersEdit([Bind(Include = "CustomerAuditorID,UserId,UserName,FirstName,LastName,Email")] EditCustomerAuditorUserViewModel customerAuditorVM)
        {
            if (ModelState.IsValid)
            {
                CustomerAuditor customerAuditor = await customerAuditorRepository.FindByIdAsync(customerAuditorVM.CustomerAuditorID.Value);

                customerAuditor.User.Id        = customerAuditorVM.UserId;
                customerAuditor.User.UserName  = customerAuditorVM.UserName;
                customerAuditor.User.FirstName = customerAuditorVM.FirstName;
                customerAuditor.User.LastName  = customerAuditorVM.LastName;
                customerAuditor.User.Email     = customerAuditorVM.Email;

                customerAuditorRepository.Update(customerAuditor);

                return(RedirectToAction("Users"));
            }
            return(View(customerAuditorVM));
        }