public ActionResult Add(Customer customer)
        {
            if (customer.Email.Contains("alkoshop.com"))
            {
                TempData["message-no-success"] = "Nemas pravo pridavat zamestnance";
                return(RedirectToAction("Index", "Home"));
            }
            if (customer.BirthDate.Year > DateTime.Today.Year - 18)
            {
                TempData["message-no-success"] = "Pro registraci musíte být starší než 18 let!";
                TempData["addresscontainer"]   = customer.Address;
                return(RedirectToAction("Create", customer));
            }

            customer.Address = (Address)TempData["addresscontainer"];

            if (ModelState.IsValid)
            {
                AddressDao addressDao = new AddressDao();
                addressDao.Create(customer.Address);

                CustomerDao customerDao = new CustomerDao();
                customerDao.Create(customer);

                TempData["message-success"] = "Registrace proběhla úspěšně prosím přihlaste se";
                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Create", customer));
        }
        public HttpResponseMessage Create(Address address)
        {
            Guid idAddressReply = Guid.Empty;

            try
            {
                if (ValidationAddressFields(address, true))
                {
                    if (dao.Create(address))
                    {
                        httpStatus     = HttpStatusCode.OK;
                        idAddressReply = address.IdAddress;
                        replyMessage   = "Cadastro de endereço realizado com sucesso";
                    }
                    else
                    {
                        throw new System.InvalidOperationException("Erro ao cadastrar endereço, por favor contate o suporte");
                    }
                }
            }
            catch (Exception ex)
            {
                httpStatus   = HttpStatusCode.InternalServerError;
                replyMessage = ex.Message;
            }

            return(Request.CreateResponse(httpStatus, idAddressReply));
        }
Example #3
0
        public ActionResult AddUser(FitnessUser fitnessUser, HttpPostedFileBase picture)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (picture != null)
                    {
                        ImageClass.ImageMethod(picture, "FitnessUser", out string bigImageName, out string smallImageName, out string tempData);

                        if (tempData != null)
                        {
                            TempData["warning"] = tempData;
                        }
                        fitnessUser.BigImageName   = bigImageName;
                        fitnessUser.SmallImageName = smallImageName;
                    }
                    UserDao    uDao = new UserDao();
                    AddressDao aDao = new AddressDao();
                    Address    a    = new Address();

                    fitnessUser.Role     = new RoleDao().GetById(399);
                    fitnessUser.Password = PasswordHash.CreateHash(fitnessUser.Password);
                    a = fitnessUser.Address;

                    if (uDao.LoginExist(fitnessUser.Login) == false)
                    {
                        aDao.Create(a);
                        fitnessUser.Address = a;
                        uDao.Create(fitnessUser);
                    }
                    else
                    {
                        TempData["warning"] = "Uživatel pod tímto loginem již existuje!";
                        return(View("CreateUser", fitnessUser));
                    }
                }
                else
                {
                    return(View("CreateUser", fitnessUser));
                }
                if (TempData["warning"] == null)
                {
                    TempData["succes"] = "Registrace proběhla úspěšně.";
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return(RedirectToAction("Index", "Home"));
        }
Example #4
0
        public ActionResult Create(bool newAddress)
        {
            Address    address;
            AddressDao addressDao = new AddressDao();

            if (newAddress)
            {
                address = TempData["addressOrder"] as Address;
                addressDao.Create(address);
            }
            else
            {
                address = (Session["User"] as DataAccess.Model.Customer).Address;
            }

            Order order = new Order();

            order.Status = "new";
            DateTime dateTime = DateTime.Now;

            order.Customer = (Session["User"] as DataAccess.Model.Customer);
            order.Date     = dateTime;
            order.Address  = address;
            IList <CartItem>     cartItems     = (Session["cart"] as List <CartItem>);
            IList <ProductOrder> productOrders = new List <ProductOrder>();

            int totalPrice = 0;

            foreach (CartItem cartItem in cartItems)
            {
                ProductOrder productOrder = new ProductOrder(cartItem.ProductId, cartItem.PricePerUnit, cartItem.NumberOfUnits, 0);
                productOrders.Add(productOrder);
                totalPrice += (cartItem.PricePerUnit * cartItem.NumberOfUnits);
            }
            order.TotalPrice = totalPrice;

            ViewBag.TotalPrice = totalPrice;
            ViewBag.Order      = order;

            TempData["potentialOrder"]         = order;
            TempData["potentialProductOrders"] = productOrders;
            TempData["potentialAddress"]       = address;
            TempData["newAddress"]             = newAddress;
            return(View(cartItems));
        }