Exemplo n.º 1
0
 public IActionResult Register(User NewUser)
 {
     if (ModelState.IsValid)
     {
         // If a User exists with provided email
         if (dbContext.Users.Any(u => u.Email == NewUser.Email))
         {
             // Manually add a ModelState error to the Email field, with provided
             // error message
             ModelState.AddModelError("Email", "Email already in use!");
             return(View("Index"));
             // You may consider returning to the View at this point
         }
         else
         {
             User newUser = new User()
             {
                 Name     = NewUser.Name,
                 Email    = NewUser.Email,
                 Password = NewUser.Password,
             };
             PasswordHasher <User> Hasher = new PasswordHasher <User>();
             newUser.Password = Hasher.HashPassword(newUser, newUser.Password);
             dbContext.Add(newUser);
             dbContext.SaveChanges();
             return(Redirect("LoginRender"));
         }
     }
     else
     {
         System.Console.WriteLine("This form was not valid.");
         return(View("Index"));
     }
 }
Exemplo n.º 2
0
 public void UpdateProductType(ProductType ProductType)
 {
     using (var context = new ACContext())
     {
         context.Entry(ProductType).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void DeleteProductSpecMapp(ProductSpecMapp productSpecMapp)
 {
     using (var context = new ACContext())
     {
         context.Entry(productSpecMapp).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 4
0
 public void UpdateBrand(Brand brand)
 {
     using (var context = new ACContext())
     {
         context.Entry(brand).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public void DeleteCategory(Category category)
 {
     using (var context = new ACContext())
     {
         context.Entry(category).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public void SaveProductType(ProductType ProductType)
 {
     using (var context = new ACContext())
     {
         ProductType.RowAddDate = System.DateTime.Now;
         context.ProductType.Add(ProductType);
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
 public void SaveBrand(Brand brand)
 {
     using (var context = new ACContext())
     {
         brand.RowAddDate = System.DateTime.Now;
         context.Brands.Add(brand);
         context.SaveChanges();
     }
 }
Exemplo n.º 8
0
 public void SaveCategory(Category category)
 {
     using (var context = new ACContext())
     {
         category.RowAddDate = System.DateTime.Now;
         context.Categories.Add(category);
         context.SaveChanges();
     }
 }
 public void SaveProductSpecMapp(ProductSpecMapp productSpecMapp)
 {
     using (var context = new ACContext())
     {
         //productSpecMapp.RowAddDate = System.DateTime.Now;
         //context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;
         context.ProductSpecMapps.Add(productSpecMapp);
         context.SaveChanges();
     }
 }
Exemplo n.º 10
0
        //public List<Product> GetProducts(string ProductSearch)
        //{
        //    using (var context = new ACContext())
        //    {
        //        return context.Products.ToList().FindAll(ProductSearch);
        //    }
        //}
        public int SaveProduct(Product product)
        {
            int id = 0;

            using (var context = new ACContext())
            {
                product.RowAddDate = System.DateTime.Now;
                //context.Entry(product.Category).State = System.Data.Entity.EntityState.Unchanged;
                context.Products.Add(product);
                context.SaveChanges();
                id = product.ID;
            }
            return(id);
        }
Exemplo n.º 11
0
 //public void UpdateProduct(Product product)
 //{
 //    using (var context = new ACContext())
 //    {
 //        context.Entry(product).State = System.Data.Entity.EntityState.Modified;
 //        context.SaveChanges();
 //    }
 //}
 public void DeleteProductSpecMapp(int ProductID)
 {
     using (var context = new ACContext())
     {
         string error;
         try
         {
             //var productSpecMapp = instance.GetProductSpecMapp(ProductID);
             //context.ProductSpecMapps.RemoveRange(productSpecMapp);
             context.ProductSpecMapps.RemoveRange(context.ProductSpecMapps.Where(x => x.ProductID == ProductID));
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             error = ex.Message;
         }
     }
 }
Exemplo n.º 12
0
        public IActionResult CreateEvent(Event e, string durationType)
        {
            int? userId  = HttpContext.Session.GetInt32("UserId");
            User planner = dbContext.Users.FirstOrDefault(u => u.UserId == userId);

            e.Planner = planner;

            if (ModelState.IsValid)
            {
                e.EventDateTime = e.EventDate.Date.Add(e.EventTime.TimeOfDay);
                e.Duration      = e.Duration + " " + durationType;
                dbContext.Add(e);
                dbContext.SaveChanges();
                return(RedirectToAction("Home"));
            }
            else
            {
                string userName = HttpContext.Session.GetString("UserName");
                ViewBag.UserId   = userId;
                ViewBag.UserName = userName;
                System.Console.WriteLine("NOT VALID");
                return(View("NewEvent"));
            }
        }
Exemplo n.º 13
0
 public IActionResult Register(User newUser)
 {
     if (ModelState.IsValid)
     {
         var dbInUser = context.UserList.FirstOrDefault(u => u.Email == newUser.Email);
         if (dbInUser != null)
         {
             ModelState.AddModelError("Email", "This Email is already in use");
         }
         else
         {
             PasswordHasher <User> PWHasher = new PasswordHasher <User>();
             newUser.Password = PWHasher.HashPassword(newUser, newUser.Password);
             context.UserList.Add(newUser);
             context.SaveChanges();
             HttpContext.Session.SetInt32("UserId", newUser.UserId);
             return(Redirect("/dashboard"));
         }
     }
     return(View("Index"));
 }