Example #1
0
        public IActionResult CreateCustomer(RegisterViewModel model)
        {
            List <Customer> AllCustomers = _context.customers.ToList();

            @ViewBag.customers = AllCustomers;
            List <Customer> CustomerMatch = _context.customers.Where(customer => customer.name == model.name).ToList();

            if (CustomerMatch.Count > 0)
            {
                @ViewBag.existing = "This customer already exists!";
                return(View("Customers"));
            }
            if (ModelState.IsValid)
            {
                Customer newCustomer = new Customer {
                    name = model.name
                };
                _context.Add(newCustomer);
                _context.SaveChanges();
                return(RedirectToAction("Customers"));
            }
            else
            {
                return(View("Customers"));
            }
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("short_desc,desc,is_in_camp,is_in_stock,quantity,tax_id,mensei_id,id,name,is_active")] Products products, string price, string camp_price, string categories)
        {
            //formdan double gelmesi gereken bilgi bölgesel farklılıklar nedeniyle tamsayı olarak dönüşüyor.
            //Alttaki ekle bu durum düzeltiliyor.
            products.price      = Tools.toDouble(price);
            products.camp_price = Tools.toDouble(camp_price);
            products.is_delete  = false;
            products.c_date     = DateTime.Now;
            products.seo_url    = Tools.toSlug(products.name);
            if (ModelState.IsValid)
            {
                _context.Add(products);

                _context.SaveChanges();
                List <PrelCs> prelc = new List <PrelCs>();
                foreach (var item in categories.Split(","))
                {
                    prelc.Add(new PrelCs()
                    {
                        ProductId  = products.id,
                        CategoryId = Int32.Parse(item)
                    });
                }

                _context.AddRange(prelc);
                _context.SaveChanges();
                FileUploadAndBound(products.id);
            }

            ViewData["mensei_id"]  = new SelectList(_context.Mensei, "id", "name", products.mensei_id);
            ViewData["tax_id"]     = new SelectList(_context.Tax, "id", "name", products.tax_id);
            ViewData["Categories"] = categories;
            return(View(products));
        }
Example #3
0
        public IActionResult Add(Customer model)
        {
            if (ModelState.IsValid)
            {
                var customerCheck = _eCommerceContext.Customer.Any(Customer => Customer.Name == model.Name);
                if (customerCheck == false)
                {
                    Customer newCustomer = new Customer
                    {
                        Name      = model.Name,
                        CreatedAt = DateTime.Now,
                        UpdatedAt = DateTime.Now
                    };
                    _eCommerceContext.Add(newCustomer);
                    _eCommerceContext.SaveChanges();
                    return(RedirectToAction("Customers"));
                }
                else
                {
                    ViewBag.Messages = "Customer already registered!";
                }
            }
            List <Customer> AllCustomers = _eCommerceContext.Customer
                                           .ToList();

            ViewBag.AllCustomers = AllCustomers;
            return(View("Customers"));
        }
Example #4
0
 public IActionResult AddCustomer(Customer customer)
 {
     if (ModelState.IsValid)
     {
         _context.Add(customer);
         _context.SaveChanges();
         return(Redirect("customers"));
     }
     return(View("Customer"));
 }
Example #5
0
        public IActionResult Registration(RegUser form)
        {
            if (ModelState.IsValid)
            {
                if (dbContext.Customers.Any(u => u.Email == form.RegEmail))
                {
                    ModelState.AddModelError("Email", "This Email already exist");
                    return(View());
                }

                PasswordHasher <RegUser> Hasher = new PasswordHasher <RegUser>();
                form.RegPassword = Hasher.HashPassword(form, form.RegPassword);

                Customer newCustomer = new Customer(form);
                dbContext.Add(newCustomer);
                dbContext.SaveChanges();

                Customer CustomerInfo = dbContext.Customers
                                        .SingleOrDefault(u => u.Email == form.RegEmail);
                HttpContext.Session.SetInt32("CustomerID", CustomerInfo.CustomerId);

                return(RedirectToAction("Success"));
            }
            return(View());
        }
        private void ProblemFourteen()
        {
            // Add the product you create to the user we created in the ShoppingCart junction table using LINQ.
            var user       = _context.ShoppingCarts.Include(u => u.User.Email == "*****@*****.**");
            var addProduct = _context.ShoppingCarts.Include(p => p.Product.Name == "Remote Controlled Car").Where(u => user.Any(e => e.UserId == e.UserId)).ToList();

            _context.Add(addProduct);
            _context.SaveChanges();
        }
        public async Task <IActionResult> Create([Bind("desc,image_url,id,name,c_date,seo_url,is_active,is_delete")] Categories categories)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categories);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(categories));
        }
Example #8
0
        public async Task <IActionResult> Create([Bind("Id,Title")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Example #9
0
        public async Task <IActionResult> Create([Bind("value,id,name,c_date,seo_url,is_active,is_delete")] Menseis menseis)
        {
            if (ModelState.IsValid)
            {
                _context.Add(menseis);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(menseis));
        }
        public async Task <IActionResult> Create([Bind("id,ProductId,CategoryId")] PrelCs prelCs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(prelCs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(prelCs));
        }
Example #11
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,ProductCatagory,ProductBrand,ProductCode,ProductImageUrl")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductCatagory"] = new SelectList(_context.ProductCatagory, "CatagoryId", "Catagory", product.ProductCatagory);
            return(View(product));
        }
Example #12
0
        public async Task <IActionResult> Create([Bind("ClientId,address,city,country,postcode,addresstype,id,name,c_date,seo_url,is_active,is_delete")] Addresses addresses)
        {
            if (ModelState.IsValid)
            {
                _context.Add(addresses);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientId"] = new SelectList(_context.Client, "id", "id", addresses.ClientId);
            return(View(addresses));
        }
Example #13
0
        public async Task <IActionResult> Create([Bind("ClientId,emailaddress,id,name,c_date,seo_url,is_active,is_delete")] Emails emails)
        {
            if (ModelState.IsValid)
            {
                _context.Add(emails);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ClientId"] = new SelectList(_context.Client, "id", "id", emails.ClientId);
            return(View(emails));
        }
Example #14
0
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,CategoryId,IsActive,IsDelete,CreatedDate,ModifiedDate,Description,ProductImage,IsFeatured,Quantity")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "CategoryId", "CategoryId", product.CategoryId);
            return(View(product));
        }
Example #15
0
        public IActionResult Signin(SignInModel model, IFormFile file)
        {
            string eUsername = SecurityModel.Encrypt(model.Uname);
            string ePassword = SecurityModel.Encrypt(model.Upass);
            string seoUrl    = Tools.toSlug(model.Uname);
            string aCode     = Tools.generateActivationCode();
            string imageUrl  = null;

            if (file != null && file.Length > 0)
            {
                try
                {
                    string newFileName = seoUrl + DateTime.Now.ToString("_ddMMyyyy_HHmmss") + "." + file.FileName.Split('.').LastOrDefault();

                    var originalDirectory = Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\img\profileImages", newFileName);

                    using (var stream = new FileStream(originalDirectory, FileMode.Create))
                    {
                        file.CopyTo(stream);
                    }
                    imageUrl = "/img/profileImages/" + newFileName;
                }
                catch (Exception ex)
                {
                }
            }
            Clients client = new Clients()
            {
                name            = model.Name,
                desc            = model.Desc,
                is_active       = false,
                is_delete       = false,
                is_corparate    = model.Is_corparate,
                tcno            = model.Tcno,
                uname           = eUsername,
                upass           = ePassword,
                c_date          = DateTime.Now,
                seo_url         = seoUrl,
                activation_code = aCode,
                image_url       = imageUrl,
                email           = model.Email
            };

            _context.Add(client);
            _context.SaveChanges();
            string localHost     = _httpContextAccessor.HttpContext.Request.Host.Value;
            string aCodeMailBody = "<a href ='http://" + localHost +
                                   "/musteri/activateclient/?activation_code=" + aCode +
                                   "&username="******"'>Aktive Edin</a>";

            Tools.sendMail(model.Email, "Aktivasyon Bilgisi", aCodeMailBody);
            return(View(model));
        }
Example #16
0
        public IActionResult newProduct(Product newProduct)
        {
            // Check initial ModelState
            if (ModelState.IsValid)
            {
                dbContext.Add(newProduct);
                dbContext.SaveChanges();

                return(RedirectToAction("Products"));
            }

            return(View("Products"));
        }
Example #17
0
        public void AddItemToCart(int PID)
        {
            var Cart = this.CreateCart();

            CartItems product;

            try
            {
                product = Cart.CartItems.Where(x => x.ProductId == PID).FirstOrDefault();
            }
            catch (Exception e)
            {
                product = null;
            }

            if (product != null)
            {
                product.ProductQuantity += 1;
                _context.Update(product);
            }
            else
            {
                CartItems item = new CartItems()
                {
                    name            = Cart.name,
                    is_active       = true,
                    is_delete       = false,
                    c_date          = DateTime.Now,
                    seo_url         = Cart.seo_url,
                    ProductId       = PID,
                    ProductQuantity = 1,
                    CartId          = Cart.id
                };
                _context.Add(item);
            }
            _context.SaveChanges();
        }
Example #18
0
        public IActionResult newOrder(Order newOrder)
        {
            // add new order
            dbContext.Add(newOrder);
            dbContext.SaveChanges();

            //update the product quantity with ordered qty
            Product UpdatingProduct = dbContext.Products
                                      .FirstOrDefault(p => p.ProductId == newOrder.ProductId);

            UpdatingProduct.Quantity -= newOrder.Quantity;
            UpdatingProduct.UpdatedAt = DateTime.Now;
            dbContext.SaveChanges();

            return(RedirectToAction("Orders"));
        }
Example #19
0
        public IActionResult Create(RegisterUser model)
        {
            ViewBag.errors = new List <string>();
            ViewBag.values = new List <string> {
                "", "", "", "", "", ""
            };
            User MyUser = _context.User.Where(u => u.EmailAddress == model.EmailAddress)
                          .SingleOrDefault();

            if (MyUser == null)
            {
                if (ModelState.IsValid)
                {
                    User NewUser = new User()
                    {
                        Name         = model.Name,
                        EmailAddress = model.EmailAddress,
                        Password     = model.Password,
                        Description  = model.Description
                    };
                    _context.Add(NewUser);
                    _context.SaveChanges();
                    // Set my ID for later.
                    MyUser = _context.User.Where(u => u.EmailAddress == model.EmailAddress)
                             .SingleOrDefault();
                    HttpContext.Session.SetInt32("myID", MyUser.UserId);
                    return(RedirectToAction("Users"));
                }
                else
                {
                    ViewBag.errors = ModelState.Values;
                    ViewBag.values = new List <string> {
                        model.Name, "", model.EmailAddress, model.Password, model.ConfirmPassword, model.Description
                    };
                }
            }
            else
            {
                ViewBag.errors = ModelState.Values;
                ViewBag.values = new List <string> {
                    model.Name, "This Email Address is already in use. Please pick a different email address.", model.EmailAddress, model.Password, model.ConfirmPassword, model.Description
                };
            }
            return(View("Index"));
        }
Example #20
0
 public IActionResult CreateProduct(ProductVM model)
 {
     if (ModelState.IsValid)
     {
         Product product = new Product {
             name        = model.name,
             description = model.description,
             img_url     = model.img_url,
             quantity    = model.quantity,
             created_at  = DateTime.UtcNow,
             updated_at  = DateTime.UtcNow,
         };
         _context.Add(product);
         _context.SaveChanges();
         refreshTop15();
         return(RedirectToAction("Index"));
     }
     return(View("Index", _top15Products));
 }
        public IActionResult newCustomer(Customer newCustomer)
        {
            // Check initial ModelState
            if (ModelState.IsValid)
            {
                if (dbContext.Customers.Any(c => c.Name == newCustomer.Name))
                {
                    ModelState.AddModelError("Name", "Name already in use!");

                    return(View("Customers"));
                }

                dbContext.Add(newCustomer);
                dbContext.SaveChanges();

                return(RedirectToAction("Customers"));
            }

            return(View("Customers"));
        }
        public IActionResult register(UserViewModel NewUser, User MyNewUser)
        {
            // //Check database if there is a user with this emai already register
            List <User>   get_user_email = _context.User.Where(email => email.Email == NewUser.Email).ToList();
            List <string> error_list     = new List <string>();

            if (ModelState.IsValid)
            {
                if (get_user_email.Count > 0)
                {
                    error_list.Add("An user with this email already exists try Login!");
                }
                if (NewUser.Password != NewUser.ConfPassword)
                {
                    error_list.Add("Confirmation Password does not match your Password!");
                }
                if (error_list.Count > 0)
                {
                    ViewBag.Errors = error_list;
                    return(View("Index"));
                }
                else
                {
                    //Hash the password
                    PasswordHasher <User> hashed = new PasswordHasher <User>();
                    MyNewUser.Password = hashed.HashPassword(MyNewUser, MyNewUser.Password);
                    //If everythin good and pass validations
                    _context.Add(MyNewUser);
                    _context.SaveChanges();
                    //Save the user_id in a session
                    User get_by_email = _context.User.SingleOrDefault(user => user.Email == NewUser.Email);
                    HttpContext.Session.SetInt32("current_user_id", (int)get_by_email.UserId);
                    return(RedirectToAction("dashboard", "Dashboard"));
                }
            }
            else
            {
                return(View("Index"));
            }
        }
Example #23
0
 public void AddEntity(object model)
 {
     _ctx.Add(model);
 }
Example #24
0
 public long Add(Product entity)
 {
     context.Add(entity);
     return(entity.Id);
 }
Example #25
0
 public IActionResult CreateCustomer(Customer customer)
 {
     dbContext.Add(customer);
     dbContext.SaveChanges();
     return(RedirectToAction("Customers"));
 }
        public IActionResult Create(Account account)
        {
            // Checks to see if all the data fields were completed
            if (ModelState.IsValid)
            {
                // Validates that the Account user's age is over 18

                // If Account user age is over 18, create an account ( Add DB validators later )
                if (account.Age >= 18)
                {
                    // If Account user is over 18, checks for duplicate email address in the DB
                    if (dbContext.Accounts.Any(a => a.Email == account.Email))
                    {
                        // if meail exists, throws an email error and returns the Registration form
                        ModelState.AddModelError("Email", "Email is already in use!");
                        return(View("New"));
                    }

                    // Else, create the Account
                    else
                    {
                        // Sets the DateTime values for account creations
                        account.CreatedAt = DateTime.Now;
                        account.UpdatedAt = DateTime.Now;

                        // Creates a password hasher object using Identity
                        PasswordHasher <Account> Hasher = new PasswordHasher <Account>();

                        // Uses the PW 'Hasher' object ot has the userform password
                        account.Password = Hasher.HashPassword(account, account.Password);

                        // Sets the default Image URL
                        account.Image = "https://via.placeholder.com/100";

                        // Adds an Account to the DB
                        dbContext.Add(account);
                        dbContext.SaveChanges();

                        // Creates 'Logged In' status, with security validation.
                        // Each route can now check to see if the User is logged in using
                        // session data to validate a query to the DB. If the email does
                        // not match the email for the user id, then session will be cleared.
                        // *NOTE* this can eventually replaced with Indentity in future projects!
                        HttpContext.Session.SetString("LoggedIn", "true");
                        HttpContext.Session.SetInt32("AccountId", account.AccountId);
                        HttpContext.Session.SetString("Email", account.Email);

                        return(RedirectToAction("Index", "Products"));
                    }
                }
                else
                {
                    // If account user is under 18, throws a birthday error and returns the Registration form
                    ModelState.AddModelError("Birthday", "To create an account, you must be at least 18 years of age!");
                    return(View("New"));
                }
            }

            // If not valid, return errors
            else
            {
                // Checks age to add birthday Validator
                if (account.Age < 18)
                {
                    // If there are other errors and the registration birthday is under 18, throws a birthday error and
                    // returns the registration form
                    ModelState.AddModelError("Birthday", "A user must be over the age of 18 to register an account!");
                    return(View("New"));
                }
                else
                {
                    // If the modelstate fails and the user is over 18, returns the registration form with Data Annotation errors
                    return(View("New"));
                }
            }
        }
Example #27
0
 public void Add(Product newProduct)
 {
     _context.Add(newProduct);
     _context.SaveChanges();
 }