Esempio n. 1
0
        public static CustomerDE Translate(this CustomerSignUpModel from, CustomerDE dest = null)
        {
            var to = dest ?? new CustomerDE();

            if (to.Id <= 0)
            {
                to.Id       = from.Id;
                to.IsActive = true;
            }
            else
            {
                to.IsActive = from.IsActive;
                //to.ModifiedDate = DateTime.Now;
            }
            //to.BasicInfo.FirstName = from.FirstName;
            //to.BasicInfo.LastName = from.LastName;
            //to.BasicInfo.Email = from.Email;
            //to.BasicInfo.Password = from.Password;
            //to.BasicInfo.PhoneNumber = from.Phone;
            //to.BasicInfo.DateOfBirth = from.DateOfBirth;
            //to.BasicInfo.MeritalStatus = from.MeritalStatus;

            //to.AddressId = from.AddressId;
            //to.UserImagePath = from.UserImagePath;

            to.IsActive = from.IsActive;

            return(to);
        }
        public ActionResult CustomerSignUp(CustomerSignUpModel vm)
        {
            // Moving the data to their own containers cause it looks nicer
            var person  = vm.Person;
            var address = vm.Address;

            // Putting in the email address to the person straight away
            person.EmailAddress = vm.EmailAddress;

            // Checks to see if the person/address is saved or not
            bool isPersonSaved  = _sql.IsPersonSaved(person);
            bool isAddressSaved = _sql.IsAddressSaved(address);


            if (isPersonSaved || isAddressSaved)
            {
                if (isPersonSaved)
                {
                    if (!isAddressSaved)
                    {
                        // The person is saved, but no the address, so this adds the new address to the person
                        _sql.AddNewAddressToExistingPerson(person, address);
                    }

                    if (isAddressSaved)
                    {
                        // Checks to see if the current address is in the current person
                        bool isPersonAddressSaved = _sql.IsPersonAddressSaved(person, address);

                        if (!isPersonAddressSaved)
                        {
                            _sql.AddExistingPersonToExistingAddress(person, address);
                        }

                        return(View(vm));
                    }
                }
                else
                {
                    if (isAddressSaved)
                    {
                        // The person is not saved but the address is, this adds the new person to the address
                        _sql.AddNewPersonToExistingAddress(person, address);
                    }
                }
            }
            else
            {
                _sql.AddNewPersonInformation(person, address);
            }


            return(View(vm));
        }
Esempio n. 3
0
        public ActionResult SignUp(CustomerSignUpModel model, HttpPostedFileBase file)
        {
            Boolean isValid = true;

            ViewBag.ErrorMessageUsername    = null;
            ViewBag.ErrorMessagePassword    = null;
            ViewBag.ErrorMessageEmail       = null;
            ViewBag.ErrorMessageFirstName   = null;
            ViewBag.ErrorMessageSurName     = null;
            ViewBag.ErrorMessageBirthday    = null;
            ViewBag.ErrorMessageCountry     = null;
            ViewBag.ErrorMessageDescription = null;

            if (db.customers.Find(model.userName) != null)
            {
                model.errorMessage = "Username already exists.";
                return(View("SignUp", model));
            }
            var customers = db.customers.Include(c => c.profile);

            foreach (Customer c in customers)
            {
                if (c.profile.eMail == model.eMail)
                {
                    model.errorMessage = "E-mail already exists.";
                    return(View("SignUp", model));
                }
            }
            if (model.userName == null || model.userName.Length < 3 || model.userName.Length > 30)
            {
                ViewBag.ErrorMessageUsername = "******";
                isValid = false;
            }
            if (model.password == null || model.password.Length < 3 || model.password.Length > 30)
            {
                ViewBag.ErrorMessagePassword = "******";
                isValid = false;
            }
            if (model.eMail == null || model.eMail.Length < 3 || model.eMail.Length > 30)
            {
                ViewBag.ErrorMessageEmail = "Please enter an email address between 3 and 30 characters.";
                isValid = false;
            }
            if (model.firstName == null || model.firstName.Length < 4 || model.firstName.Length > 30)
            {
                ViewBag.ErrorMessageFirstName = "Please enter a valid first name between 3 and 30 characters.";
                isValid = false;
            }
            if (model.surname == null || model.surname.Length < 4 || model.surname.Length > 30)
            {
                ViewBag.ErrorMessageSurName = "Please enter a valid surname between 3 and 30 characters.";
                isValid = false;
            }
            if (model.birthday == null || model.birthday.ToString() == "01.01.0001 00:00:00")
            {
                ViewBag.ErrorMessageBirthday = "Please enter a birthday.";
                isValid = false;
            }
            else
            {
                DateTime today = DateTime.Now;
                var      diff  = (today - model.birthday).TotalDays;
                if (diff < 6570)
                {
                    ViewBag.ErrorMessageBirthday = "You have to be 18 Years old to register on this homepage.";
                    isValid = false;
                }
                if (diff > 43800)
                {
                    ViewBag.ErrorMessageBirthday = "Your birth date would mean you are over 120 years old. Sorry that's not possible. :-)";
                    isValid = false;
                }
            }
            if (model.countryUser == null)
            {
                ViewBag.ErrorMessageCountry = "Please select a country.";
                isValid = false;
            }
            if (model.descriptionUser != null && model.descriptionUser.Length > 300)
            {
                ViewBag.ErrorMessageDescription = "The maximum capacity are 300 characters.";
                isValid = false;
            }

            if (isValid == true)
            {
                Profile profile = new Profile
                {
                    userName        = model.userName,
                    eMail           = model.eMail,
                    password        = model.password,
                    firstName       = model.firstName,
                    surname         = model.surname,
                    birthday        = model.birthday,
                    descriptionUser = model.descriptionUser
                };

                db.profiles.Add(profile);
                db.SaveChanges();

                Customer customer = new Customer();
                try
                {
                    string fileName  = profile.userName;
                    string extension = Path.GetExtension(file.FileName);
                    fileName += extension;
                    customer.selectedPictureCustomer = "~/Content/" + fileName;
                    fileName = Path.Combine(Server.MapPath("~/Content/"), fileName);
                    file.SaveAs(fileName);
                }
                catch (Exception)
                {
                    customer.selectedPictureCustomer = "~/Content/defaultUser.png";
                }

                customer.userName    = profile.userName;
                customer.countryUser = model.countryUser;

                db.customers.Add(customer);
                db.SaveChanges();

                Session["userName"] = customer.userName;

                return(RedirectToAction("Index"));
            }

            else
            {
                return(View("SignUp", model));
            }
        }