Inheritance: System.Web.UI.Page
        public ActionResult Account()
        {
            if (Request.Cookies["role"].Value != "customer")
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var customerID = UserAccount.GetUserID();

            using (NorthwndEntities db = new NorthwndEntities())
            {
                Customer customer = db.Customers.Find(customerID);

                CustomerEdit customerEdit = new CustomerEdit
                {//inline array
                    CompanyName  = customer.CompanyName,
                    ContactName  = customer.ContactName,
                    ContactTitle = customer.ContactTitle,
                    Address      = customer.Address,
                    City         = customer.City,
                    Region       = customer.Region,
                    PostalCode   = customer.PostalCode,
                    Country      = customer.Country,
                    Phone        = customer.Phone,
                    Fax          = customer.Fax,
                    Email        = customer.Email
                };

                return(View(customerEdit));
            }

            //return View();
        }
Example #2
0
        private async void SaveButton_Click(object sender, EventArgs ea)
        {
            var waitingOverlay = new WaitingOverlay(UIScreen.MainScreen.Bounds, "Saving...");
            View.Add(waitingOverlay);

            Bindings.UpdateSourceForLastView();
            this.Model.ApplyEdit();
            try
            {
                //this.Model.GetBrokenRules();
                this.Model = await this.Model.SaveAsync();
                
                var alert = new UIAlertView();
                alert.Message = "Saved...";
                alert.AddButton("Close");
                alert.DismissWithClickedButtonIndex(0, false);
                alert.Show();
            }
            catch (Exception ex)
            {
                var alert = new UIAlertView();
                alert.Message = string.Format("the following error has occurred: {0}", ex.Message);
                alert.AddButton("Close");
                alert.DismissWithClickedButtonIndex(0, false);
                alert.Show();
            }
            finally
            {
                InitializeBindings(this.Model);
                waitingOverlay.Hide();
            }
        }
        public ActionResult Account(CustomerEdit updatedCust)
        {
            if (Request.Cookies["role"].Value != "customer")
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            using (NORTHWNDEntities db = new NORTHWNDEntities())
            {
                if (ModelState.IsValid)
                {
                    Customer customer = db.Customers.Find(UserAccount.GetUserID());
                    if (customer.CompanyName.ToLower() != updatedCust.CompanyName.ToLower())
                    {
                        // Ensure that the CompanyName is unique
                        if (db.Customers.Any(c => c.CompanyName == updatedCust.CompanyName))
                        {
                            // duplicate CompanyName
                            ModelState.AddModelError("CompanyName", "There is already a company named that");
                            return(View(updatedCust));
                        }
                    }
                    Mapper.Map(updatedCust, customer);
                    db.SaveChanges();
                    return(RedirectToAction(actionName: "Index", controllerName: "Home"));
                }
                //Validation Problem
                return(View(updatedCust));
            }
        }
Example #4
0
        public ActionResult Account()
        {
            if (Request.Cookies["role"].Value != "customer")
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewBag.CustomerID = UserAccount.GetUserID();

            using (var db = new NorthwindEntities())
            {
                Customer customer = db.Customers.Find(UserAccount.GetUserID());

                CustomerEdit EditCustomer = new CustomerEdit()
                {
                    CompanyName  = customer.CompanyName,
                    ContactName  = customer.ContactName,
                    ContactTitle = customer.ContactTitle,
                    Address      = customer.Address,
                    City         = customer.City,
                    Region       = customer.Region,
                    PostalCode   = customer.PostalCode,
                    Country      = customer.Country,
                    Phone        = customer.Phone,
                    Fax          = customer.Fax,
                    Email        = customer.Email
                };

                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
        }
        public async Task <bool> UpdateCustomerAsync(CustomerEdit note)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = await
                             ctx
                             .Customers
                             .Where(e => e.CustomerId == note.CustomerId)
                             .FirstOrDefaultAsync();

                entity.FirstName       = note.FirstName;
                entity.LastName        = note.LastName;
                entity.Username        = note.Username;
                entity.Phone           = note.Phone;
                entity.Email           = note.Email;
                entity.Address         = note.Address;
                entity.MembershipLevel = note.MembershipLevel;
                entity.Latitude        = note.Latitude;
                entity.Longitude       = note.Longitude;

                //entity.RestaurantId = note.RestaurantId;

                //ctx.Entry(entity).State = EntityState.Modified;
                return(await ctx.SaveChangesAsync() == 1);
            }
        }
Example #6
0
        private async void SaveButton_Click(object sender, EventArgs ea)
        {
            var waitingOverlay = new WaitingOverlay(UIScreen.MainScreen.Bounds, "Saving...");

            View.Add(waitingOverlay);

            Bindings.UpdateSourceForLastView();
            this.Model.ApplyEdit();
            try
            {
                //this.Model.GetBrokenRules();
                this.Model = await this.Model.SaveAsync();

                var alert = new UIAlertView();
                alert.Message = "Saved...";
                alert.AddButton("Close");
                alert.DismissWithClickedButtonIndex(0, false);
                alert.Show();
            }
            catch (Exception ex)
            {
                var alert = new UIAlertView();
                alert.Message = string.Format("the following error has occurred: {0}", ex.Message);
                alert.AddButton("Close");
                alert.DismissWithClickedButtonIndex(0, false);
                alert.Show();
            }
            finally
            {
                InitializeBindings(this.Model);
                waitingOverlay.Hide();
            }
        }
Example #7
0
        public async Task <ActionResult> Edit(int id)
        {
            var service = CreateCustomerService();
            var detail  = await service.GetCustomerByIdAsync(id);

            var model =
                new CustomerEdit
            {
                CustomerId        = detail.CustomerId,
                FirstName         = detail.FirstName,
                LastName          = detail.LastName,
                Username          = detail.Username,
                Phone             = detail.Phone,
                Address           = detail.Address,
                Email             = detail.Email,
                ContactPreference = detail.ContactPreference,
                MembershipLevel   = detail.MembershipLevel,
                Latitude          = detail.Latitude,
                Longitude         = detail.Longitude
            };



            return(View(model));
        }
        public bool UpdateCustomer(CustomerEdit note)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Customers
                    .Where(e => e.CustomerId == note.CustomerId)
                    .FirstOrDefault();

                entity.FirstName       = note.FirstName;
                entity.LastName        = note.LastName;
                entity.Username        = note.Username;
                entity.Phone           = note.Phone;
                entity.Email           = note.Email;
                entity.Address         = note.Address;
                entity.MembershipLevel = note.MembershipLevel;
                entity.Latitude        = note.Latitude;
                entity.Longitude       = note.Longitude;
                //entity.RestaurantId = note.RestaurantId;


                return(ctx.SaveChanges() == 1);
            }
        }
Example #9
0
        public ActionResult EditPost(int id, string returnUrl)
        {
            var customer = _customerService.Customers.FirstOrDefault(x => x.Id == id && x.IsActive);

            if (customer == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var viewModel = new CustomerEdit(customer);

            if (!TryUpdateModel(viewModel) || !ModelState.IsValid)
            {
                return(View(viewModel));
            }

            try
            {
                var model = viewModel.ToCustomer();
                _customerService.Create(model);
            }
            catch (Exception ex)
            {
                return(View(viewModel));

                throw ex;
            }

            //return RedirectToAction("Create", "Order");
            return(Redirect(returnUrl));
        }
Example #10
0
        public ActionResult Put(int id, [FromBody] CustomerEdit model)
        {
            Customer customer = _ctx.Customer.Find(id);

            if (customer != null)
            {
                customer.Id          = customer.Id; // just for clarity but we do not change it
                customer.Title       = model.Title;
                customer.Firstname   = model.Firstname;
                customer.Lastname    = model.Lastname;
                customer.DateOfBirth = model.DateOfBirth;
                customer.Address     = model.Address;
                customer.Country     = model.Country;
                customer.PostalCode  = model.PostalCode;

                _ctx.Customer.Update(customer);   // update like this to avoid changing pk
                _ctx.SaveChanges();

                return(new OkObjectResult(customer));
            }
            else
            {
                return(new NotFoundObjectResult("Customer not found, check for valid customer id"));
            }
        }
Example #11
0
        public async Task <ActionResult> Edit(int customerId, CustomerEdit model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                if (model.Id != customerId)
                {
                    ModelState.AddModelError("", "Id mismatch.");

                    return(View(model));
                }

                var service = CreateCustomerService();

                if (!await service.UpdateCustomerAsync(model))
                {
                    ModelState.AddModelError("", "Could not update customer.");

                    return(View(model));
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(model));
            }
        }
Example #12
0
        public bool UpdateCustomer(CustomerEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Customers.Single(e => e.CustomerId == model.CustomerId && e.User == _userId);
                if (model.FirstName != null)
                {
                    entity.FirstName = model.FirstName;
                }
                ;
                if (model.LastName != null)
                {
                    entity.LastName = model.LastName;
                }
                ;
                if (model.Address != null)
                {
                    entity.Address = model.Address;
                }
                ;
                if (model.Phone != null)
                {
                    entity.Phone = model.Phone;
                }
                ;

                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id, CustomerEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.CustomerId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateCustomerService();

            if (service.UpdateCustomer(model))
            {
                TempData["SaveResult"] = $"{model.FirstName} {model.LastName} Was Updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", $"{model.FirstName} {model.LastName} Could Not Be Updated.");

            var locationList = new SelectList(service.LocationList(), "LocationId", "FullLocation", model.LocationId);

            ViewBag.LocationId = locationList;

            return(View(model));
        }
Example #14
0
        public ActionResult Account()
        {
            // cookies
            if (Request.Cookies["role"].Value != "customer")
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //ViewBag.CustomerID = UserAccount.GetUserID();
            using (NORTHWNDEntities db = new NORTHWNDEntities())
            {
                // find customer using CustomerID (stored in authentication ticket)
                Customer customer = db.Customers.Find(UserAccount.GetUserID());
                // display original values in textboxes when customer is editing data
                CustomerEdit EditCustomer = new CustomerEdit()
                {
                    CompanyName  = customer.CompanyName,
                    ContactName  = customer.ContactName,
                    ContactTitle = customer.ContactTitle,
                    Address      = customer.Address,
                    City         = customer.City,
                    Region       = customer.Region,
                    PostalCode   = customer.PostalCode,
                    Country      = customer.Country,
                    Phone        = customer.Phone,
                    Fax          = customer.Fax,
                    Email        = customer.Email
                };
                return(View(EditCustomer));
            }
        }
Example #15
0
        protected override void Editar()
        {
            base.Editar();
            // Obtenemos el registro seleccionado y lo enviamos a las cajas de texto.

            try
            {
                if (customerInfoListBindingSource.Current == null)
                {
                    return;
                }

                var seleccionado = customerInfoListBindingSource.Current as CustomerInfo;

                // Cargamos el registro en base al ID.
                customer = CustomerEdit.GetCustomerEdit(seleccionado.ID);

                customerEditBindingSource.DataSource = customer;
                customerEditBindingSource.ResetBindings(false);
                nameTextBox.Focus();
            }
            catch (DataPortalException ex)
            {
                MessageBox.Show(ex.BusinessException.Message, "Editar", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #16
0
 public ActionResult Account()
 {
     //ViewBag.CustomerID = UserAccount.GetUserID();
     using (NorthwndEntities db = new NorthwndEntities())
     {
         // find customer using CustomerID (stored in authentication ticket)
         Customer customer = db.Customers.Find(UserAccount.GetUserID());
         // display original values in textboxes when customer is editing data
         CustomerEdit EditCustomer = new CustomerEdit()
         {
             CompanyName  = customer.CompanyName,
             ContactName  = customer.ContactName,
             ContactTitle = customer.ContactTitle,
             Address      = customer.Address,
             City         = customer.City,
             Region       = customer.Region,
             PostalCode   = customer.PostalCode,
             Country      = customer.Country,
             Phone        = customer.Phone,
             Fax          = customer.Fax,
             Email        = customer.Email
         };
         return(View(EditCustomer));
     }
 }
Example #17
0
        public void Edit()
        {
            int customerId   = (int)customerGridView.SelectedRows[0].Cells[0].Value;
            var customerEdit = new CustomerEdit(customerId);

            customerEdit._refreshDataGridView += new CustomerEdit.DoEvent(LoadDataGrid);
            customerEdit.Show();
        }
        public IActionResult Create(CustomerEdit customerEdit)
        {
            var customer = new Customer();

            customer.CustomerName = customerEdit.CustomerName;
            customer.Address      = customerEdit.Address;
            _mongo.Add(customer);
            return(View("Details", customer));
        }
        public ActionResult Create(string returnUrl)
        {
            var viewModel = new CustomerEdit(new Data.Models.Customer())
            {
                ReturnUrl = returnUrl
            };

            return(View(viewModel));
        }
Example #20
0
 private void InitializeBindings(Library.CustomerEdit model)
 {
     this.Model = model;
     this.Model.BeginEdit();
     this.Bindings.RemoveAll();
     Bindings.Add(((MainView)View).txtId, "Text", this.Model, "Id", BindingDirection.OneWay);
     Bindings.Add(((MainView)View).txtName, "Text", this.Model, "Name", BindingDirection.TwoWay);
     Bindings.Add(((MainView)View).txtStatus, "Text", this.Model, "Status", BindingDirection.OneWay);
 }
Example #21
0
 private void InitializeBindings(Library.CustomerEdit model)
 {
     this.Model = model;
     this.Model.BeginEdit();
     this.Bindings.RemoveAll();
     Bindings.Add(((MainView)View).txtId, "Text", this.Model, "Id", BindingDirection.OneWay);
     Bindings.Add(((MainView)View).txtName, "Text", this.Model, "Name", BindingDirection.TwoWay);
     Bindings.Add(((MainView)View).txtStatus, "Text", this.Model, "Status", BindingDirection.OneWay);
 }
Example #22
0
        public ActionResult Edit(CustomerEdit customeredit)
        {
            List <SalePoint> salepointlist = AgroExpressDBAccess.GetallEnabledSalePoint();

            if (salepointlist != null)
            {
                customeredit.salepointlist = salepointlist.Select(x => new SelectListItem
                {
                    Value = x.PKSalePointID.ToString(),
                    Text  = x.SalePointName
                });
            }

            List <Area> arealist = AgroExpressDBAccess.GetallEnabledArea();

            if (arealist != null)
            {
                customeredit.arealist = arealist.Select(x => new SelectListItem
                {
                    Value = x.PKAreaId.ToString(),
                    Text  = x.AreaName
                });
            }

            List <SubArea> sarealist = AgroExpressDBAccess.GetallEnabledSubArea();

            if (sarealist != null)
            {
                customeredit.subarealist = sarealist.Select(x => new SelectListItem
                {
                    Value = x.PKSubAreaId.ToString(),
                    Text  = x.SubAreaName
                });
            }
            if (ModelState.IsValid)
            {
                var userinfo = AgroExpressDBAccess.IsUserExist(customeredit.UserName);
                if (userinfo != null)
                {
                    if (userinfo.PkUserID != customeredit.LoginUserID)
                    {
                        ModelState.AddModelError("UserName", "User Name Already Exists!!!");
                        return(View(customeredit));
                    }
                }

                if (AgroExpressDBAccess.UpdateCustomer(customeredit))
                {
                    ViewBag.success = "Customer added successfully";

                    return(RedirectToAction("EnabledCustomer"));
                }
            }

            return(View(customeredit));
        }
Example #23
0
        protected override void Nuevo()
        {
            base.Nuevo();
            customer = CustomerEdit.NewCustomerEdit();

            customerEditBindingSource.DataSource = customer;
            customerEditBindingSource.ResetBindings(false);

            nameTextBox.Focus();
        }
Example #24
0
        public IActionResult Edit([FromBody] CustomerEdit customerEdit)
        {
            Response <Customer> response = new Response <Customer>();
            Customer            customer = _customerRepository.Update(customerEdit.ToCostumer());

            customer.Senha = null;

            response.Data = customer;
            return(Ok(response));
        }
        public ActionResult Edit(int id)
        {
            var service = CreateCustomerService();
            var detail  = service.GetCustomerById(id);
            var model   =
                new CustomerEdit
            {
                Id   = detail.Id,
                Name = detail.Name
            };

            return(View(model));
        }
Example #26
0
        private void repositoryItemButtonEdit1_Click(object sender, EventArgs e)
        {
            var customer = this.OrderVM.Orders[gridView.FocusedRowHandle]?.Customer;

            if (customer != null)
            {
                var edit = new CustomerEdit(customer);
                if (edit.ShowDialog() == DialogResult.OK)
                {
                    gridControl.RefreshDataSource();
                }
            }
        }
Example #27
0
        public bool UpdateCustomer(CustomerEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Customers.Single(e => e.Id == model.Id && e.OwnerId == _userId);

                entity.Id   = model.Id;
                entity.Name = model.Name;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #28
0
 public static void Map(Customer customer, CustomerEdit UpdatedCustomer)
 {
     customer.CompanyName  = UpdatedCustomer.CompanyName;
     customer.Address      = UpdatedCustomer.Address;
     customer.City         = UpdatedCustomer.City;
     customer.ContactName  = UpdatedCustomer.ContactName;
     customer.ContactTitle = UpdatedCustomer.ContactTitle;
     customer.Country      = UpdatedCustomer.Country;
     customer.Email        = UpdatedCustomer.Email;
     customer.Fax          = UpdatedCustomer.Fax;
     customer.Phone        = UpdatedCustomer.Phone;
     customer.PostalCode   = UpdatedCustomer.PostalCode;
     customer.Region       = UpdatedCustomer.Region;
 }
Example #29
0
        public IHttpActionResult Put(CustomerEdit customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateCustomerService();

            if (!service.UpdateCustomerInformations(customer))
            {
                return(InternalServerError());
            }
            return(Ok("The customer has been updated."));
        }
        public ActionResult Edit(int id)
        {
            var service = CreateCustomerService();
            var detail  = service.GetCustomerById(id);
            var model   = new CustomerEdit
            {
                CustomerId = detail.CustomerId,
                FirstName  = detail.FirstName,
                LastName   = detail.LastName,
                Email      = detail.Email
            };

            return(View(model));
        }
        public IHttpActionResult Put([FromBody] CustomerEdit customer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateCustomerSevice();

            if (!service.UpdateCustomer(customer))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
        public bool UpdateCustomerInformations(CustomerEdit customer)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = ctx.Customers.Single(e => e.CustomerId == customer.CustomerId && e.OwnerId == _UserId);
                entity.CustomerId   = customer.CustomerId;
                entity.FirstName    = customer.FirstName;
                entity.LastName     = customer.LastName;
                entity.EmailAddress = customer.Email;
                entity.PhoneNumber  = customer.PhoneNumber;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #33
0
        public async override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (Initialized) return;
            Initialized = true;

            this.View = new MainView();

            // create binding manager
            Bindings = new BindingManager(this.View);

            ((MainView)this.View).btnSave.TouchUpInside += SaveButton_Click;
            ((MainView)this.View).btnCancel.TouchUpInside += CancelButton_Click;
            ((MainView)this.View).btnMarkForDelete.TouchUpInside += DeleteButton_Click;

            ((MainView)this.View).txtName.ShouldReturn += (textField) =>
            {
              textField.ResignFirstResponder();
              return true;
            };

            var waitingOverlay = new WaitingOverlay(UIScreen.MainScreen.Bounds, "Loading...");
            View.Add(waitingOverlay);

            try
            {
                this.Model = await CustomerEdit.GetCustomerEditAsync(1);
                InitializeBindings(this.Model);
            }
            catch (Exception ex)
            {
                var alert = new UIAlertView();
                alert.Message = string.Format("the following error has occurred: {0}", ex.Message);
                alert.AddButton("Close");
                alert.DismissWithClickedButtonIndex(0, false);
                alert.Show();
            }
            finally
            {
                waitingOverlay.Hide();
            }
        }
Example #34
0
 public void Delete(CustomerEdit obj)
 {
 }
Example #35
0
 public CustomerEdit Update(CustomerEdit obj)
 {
   MarkOld(obj);
   return obj;
 }