Exemplo n.º 1
0
        public ActionResult TecknaKampanjAvtal(SignDealViewModel m)
        {
            if (!m.CustomerInfo.LetUsGetInfo)
            {
                if (String.IsNullOrEmpty(m.CustomerInfo.PropertyCode))
                {
                    ModelState.AddModelError("", "Du måste ange ett AnläggningsID");
                }
                if (String.IsNullOrEmpty(m.CustomerInfo.AreaCode))
                {
                    ModelState.AddModelError("", "Du måste ange ett områdesID");
                }
                if (String.IsNullOrEmpty(m.CustomerInfo.StartDate.ToLongDateString()) || m.CustomerInfo.StartDate.Date < DateTime.Now.Date)
                {
                    ModelState.AddModelError("", "Du måste ange ett datum som inte är tidigare än dagens datum");
                }
            }
            var Customer = new CustomerRepository();

            if (ModelState.IsValid)
            {
                var model = new AddCustomerAdminViewModel();
                model          = m.CustomerInfo;
                model.IpAdress = Request.UserHostAddress;
                model.ClientId = m.ScrapeId;
                m.IsClient     = true;
                Customer.SaveCustomerAdminModel(model);
                _email.SendEmailAsync(m);
                return(RedirectToAction("Thanks"));
            }
            var helper    = new CustomerDealRepository();
            var failmodel = helper.GetClientModel(m.ScrapeId);

            return(View("SignClientDeal", failmodel));
        }
Exemplo n.º 2
0
        private void SaveClients(AddCustomerAdminViewModel model)
        {
            if (model.LetUsGetInfo)
            {
                var customer = new Customer
                {
                    Address           = model.Address,
                    City              = model.City,
                    Email             = model.Email,
                    Firstname         = model.Firstname,
                    IpAdress          = model.IpAdress,
                    Lastname          = model.Lastname,
                    SocialSecurity    = model.SocialSecurity,
                    HasConfirmed      = model.HasConfirmed,
                    Paymentmethod     = model.Paymentmethod,
                    Postnumber        = model.Postnumber,
                    ClientId          = model.ClientId,
                    LetUsGetInfo      = model.LetUsGetInfo,
                    DaySigned         = DateTime.Now,
                    PaymentAddress    = model.FakturaAddress != null ? model.FakturaAddress : model.Address,
                    PaymentCity       = model.FakturaCity != null ? model.FakturaCity : model.City,
                    PaymentPostnumber = model.FakturaPostnumber != null ? model.FakturaPostnumber : model.Postnumber
                };
                db.Customers.Add(customer);
                db.SaveChanges();
            }
            else
            {
                var customer = new Customer
                {
                    Address           = model.Address,
                    City              = model.City,
                    DaySigned         = DateTime.Now,
                    Email             = model.Email,
                    Firstname         = model.Firstname,
                    IpAdress          = model.IpAdress,
                    Lastname          = model.Lastname,
                    SocialSecurity    = model.SocialSecurity,
                    HasConfirmed      = model.HasConfirmed,
                    Paymentmethod     = model.Paymentmethod,
                    Postnumber        = model.Postnumber,
                    ClientId          = model.ClientId,
                    LetUsGetInfo      = model.LetUsGetInfo,
                    AreaCode          = model.AreaCode,
                    StartDate         = model.StartDate,
                    PropertyCode      = model.PropertyCode,
                    PaymentAddress    = model.FakturaAddress != null ? model.FakturaAddress : model.Address,
                    PaymentCity       = model.FakturaCity != null ? model.FakturaCity : model.City,
                    PaymentPostnumber = model.FakturaPostnumber != null ? model.FakturaPostnumber : model.Postnumber
                };

                db.Customers.Add(customer);
                db.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public ActionResult AddCustomer(AddCustomerAdminViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.IpAdress = Request.UserHostAddress;
                Customer.SaveCustomerAdminModel(model);
                return(RedirectToAction("ListCustomers"));
            }

            var failmodel = Customer.GetAdminModel();

            return(View(failmodel));
        }
Exemplo n.º 4
0
 public void SaveCustomerAdminModel(AddCustomerAdminViewModel model)
 {
     try
     {
         if (model.ClientId != null)
         {
             SaveClients(model);
         }
         else
         {
             SaveScraped(model);
         }
     }
     catch {
         throw new Exception();
     }
 }
Exemplo n.º 5
0
        public AddCustomerAdminViewModel GetAdminModel()
        {
            AddCustomerAdminViewModel model;

            if (db.ClientModels.Any())
            {
                model = new AddCustomerAdminViewModel
                {
                    Clients = db.ClientModels.ToList()
                };
            }
            else
            {
                model = new AddCustomerAdminViewModel
                {
                    Clients = new List <ClientModel>()
                };
            }

            return(model);
        }