Exemplo n.º 1
0
        // GET: /<controller>/
        public IActionResult Add()
        {
            AddCustomerViewModel addCustomerViewModel = new AddCustomerViewModel();

            return(View(addCustomerViewModel));
        }
Exemplo n.º 2
0
        public ActionResult Add()
        {
            var model = new AddCustomerViewModel();

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Add(AddCustomerViewModel model)
        {
            FillLookups();
            string pictureName = "";

            if (ModelState.IsValid)// && model.Location.IsValid())
            {
                var newCustomerId = _customerRepository.GetAll().Last().Id + 1;

                if (!string.IsNullOrWhiteSpace(model.LogoFileName))
                {
                    bool isValidPicture;
                    pictureName = GetLabelPath(model.CustomerType == OmsCustomerType.Custom, model.LogoFileName,
                                               newCustomerId, out isValidPicture);

                    if (!isValidPicture)
                    {
                        ModelState.AddModelError(string.Empty, pictureName);
                        return(View("Add", model));
                    }
                }

                var user = new User
                {
                    FirstName = model.OrderContactFirstName,
                    LastName  = model.OrderContactLastName,
                    Email     = model.OrderContactEmail,
                    Phone     = model.OrderContactPhone,
                    Password  = model.PortalPassword,
                    IsActive  = true,
                    TypeId    = 2
                };

                _userRepository.Add(user);
                _userRepository.Save();

                var customer = new Customer
                {
                    BestBeforeDays = model.BestBeforeDays,
                    LogoTypeId     = model.UseLogoOnLabels,
                    LogoFileName   = pictureName,
                    Name           = model.CustomerName,
                    CustomerTypeId = model.CustomerType,
                    PONumber       = model.CustomerPo,
                    DistributedBy  = model.LabelDistributedBy,
                    BoxLabel       = model.BoxLabel,
                    TrayLabel      = model.TrayLabel,
                    BagLabel       = model.BagLabel,
                    User           = user,
                    IsArchived     = model.IsArchived,
                    UserId         = user.Id
                };

                _customerRepository.Add(customer);
                _customerRepository.Save();

                var products         = _productRepository.GetByCustomerType(model.CustomerType).Where(x => x.IsActive).ToList();
                var customerProducts = new List <CustomerProductData>();

                foreach (var product in products)
                {
                    customerProducts.Add(new CustomerProductData
                    {
                        CustomerId         = customer.Id,
                        ProductId          = product.Id,
                        ProductCode        = product.Code,
                        ProductDescription = product.EnglishDescription,
                        Gtin          = product.Gtin,
                        PricePerPound = product.PricePerPound
                    });
                }
                _customerProductDataRepository.AddRange(customerProducts);
                _customerProductDataRepository.Save();

                if (model.Location.IsExists())
                {
                    var location = model.Location.ToCustomerLocation();
                    location.CustomerId = customer.Id;

                    _customerLocationRepository.Add(location);
                    _customerLocationRepository.Save();
                }
                return(RedirectToAction("EditCustomer", new { customerId = customer.Id }));
            }

            foreach (var pair in model.Location.Validate())
            {
                ModelState.AddModelError(pair.Key, pair.Value);
            }

            return(View(model));
        }
        public ActionResult Create(AddCustomerViewModel form, HttpPostedFileBase UserAvatar)
        {
            if (ModelState.IsValid)
            {
                #region Check for duplicate username or email

                if (form.UserName != null)
                {
                    if (_usersRepo.UserNameExists(form.UserName))
                    {
                        ViewBag.Message       = "کاربر دیگری با همین نام کاربری در سیستم ثبت شده";
                        ViewBag.GeoDivisionId = new SelectList(_geoDivisonsRepo.GetGeoDivisionsByType((int)GeoDivisionType.State), "Id", "Title", form.GeoDivisionId);

                        return(View(form));
                    }
                }
                if (_usersRepo.PhoneNumberExists(form.PhoneNumber))
                {
                    ViewBag.Message       = "کاربر دیگری با همین شماره تلفن در سیستم ثبت شده";
                    ViewBag.GeoDivisionId = new SelectList(_geoDivisonsRepo.GetGeoDivisionsByType((int)GeoDivisionType.State), "Id", "Title", form.GeoDivisionId);

                    return(View(form));
                }
                if (_usersRepo.EmailExists(form.Email))
                {
                    ViewBag.Message       = "کاربر دیگری با همین ایمیل در سیستم ثبت شده";
                    ViewBag.GeoDivisionId = new SelectList(_geoDivisonsRepo.GetGeoDivisionsByType((int)GeoDivisionType.State), "Id", "Title", form.GeoDivisionId);

                    return(View(form));
                }
                #endregion

                #region Upload Image
                if (UserAvatar != null)
                {
                    var newFileName = Guid.NewGuid() + Path.GetExtension(UserAvatar.FileName);
                    UserAvatar.SaveAs(Server.MapPath("/Files/UserAvatars/" + newFileName));

                    form.Avatar = newFileName;
                }
                #endregion

                var userModel = new User()
                {
                    UserName    = form.UserName,
                    FirstName   = form.FirstName,
                    LastName    = form.LastName,
                    Email       = form.Email,
                    PhoneNumber = form.PhoneNumber,
                    Avatar      = form.Avatar
                };
                userModel.UserName = form.UserName ?? form.PhoneNumber;
                _usersRepo.CreateUser(userModel, form.Password);
                _usersRepo.AddUserRole(userModel.Id, StaticVariables.CustomerRoleId);

                var customer = new Customer()
                {
                    UserId        = userModel.Id,
                    IsDeleted     = false,
                    NationalCode  = form.NationalCode,
                    Address       = form.Address,
                    PostalCode    = form.PostalCode,
                    GeoDivisionId = form.GeoDivisionId
                };
                _repo.Add(customer);

                return(RedirectToAction("Index"));
            }

            ViewBag.GeoDivisionId = new SelectList(_geoDivisonsRepo.GetGeoDivisionsByType((int)GeoDivisionType.State), "Id", "Title", form.GeoDivisionId);
            return(View(form));
        }
Exemplo n.º 5
0
 public void Save(AddCustomerViewModel model)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 public ActionResult create(AddCustomerViewModel viewModel)
 {
     return(View());
 }
Exemplo n.º 7
0
 public WindowAddCustomer()
 {
     InitializeComponent();
     DataContext = new AddCustomerViewModel();
 }
Exemplo n.º 8
0
 public void Dispose()
 {
     AddCustomerViewModel = null;
     GC.SuppressFinalize(this);
     GC.Collect();
 }
Exemplo n.º 9
0
 public AddCustomerWindow(Model.MusteriModel musteri)
 {
     InitializeComponent();
     AddCustomerViewModel = new AddCustomerViewModel(musteri);
     DataContext          = AddCustomerViewModel;
 }
Exemplo n.º 10
0
        public IActionResult AddCustomerResult(AddCustomerViewModel model)
        {
            var customersViewModel = _customerService.AddCustomer(model);

            return(View("Customers", customersViewModel));
        }