Exemplo n.º 1
0
        public EditSupplierVm GetEditSupplierVm(int id)
        {
            Supplier       supplier = this.Context.Suppliers.Find(id);
            EditSupplierVm vm       = Mapper.Map <Supplier, EditSupplierVm>(supplier);

            return(vm);
        }
        public EditSupplierVm GetEditSupplierVm(int id)
        {
            var supplier = this.context.Suppliers.Find(id);

            var viewModel = new EditSupplierVm()
            {
                Id   = id,
                Name = supplier.Name
            };

            return(viewModel);
        }
        public ActionResult Edit(int id)
        {
            var httpCookie = this.Request.Cookies.Get("sessionId");

            if (httpCookie == null || !AuthenticationManager.IsAuthenticated(httpCookie.Value))
            {
                return(this.RedirectToAction("All"));
            }
            EditSupplierVm vm = this.service.GetEditSupplier(id);

            return(View(vm));
        }
        public ActionResult Edit([Bind(Include = "Id, Name, IsImporter")] EditSupplierBm bind)
        {
            var httpCookie = this.Request.Cookies.Get("sessionId");

            if (httpCookie == null || !AuthenticationManager.IsAuthenticated(httpCookie.Value))
            {
                return(this.RedirectToAction("All"));
            }

            if (!this.ModelState.IsValid)
            {
                EditSupplierVm vm = this.business.GetEditSupplierVm(bind.Id);
                return(this.View(vm));
            }

            User loggedInUser = AuthenticationManager.GetAuthenticatedUser(httpCookie.Value);

            this.business.EditSupplier(bind, loggedInUser.Id);
            return(this.RedirectToAction("All"));
        }