Beispiel #1
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            ViewBag.Title = "Регистрация";
            if (ModelState.IsValid)
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    db.Users.Add(new User {
                        Name = model.Name, Email = model.Email, Password = model.Password
                    });
                    await db.SaveChangesAsync();

                    await Authenticate(model.Email); // аутентификация

                    return(RedirectToAction("About", "Account"));
                }
                else
                {
                    ModelState.AddModelError("", "Данный Email уже используется");
                }
            }
            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> AddSneaker(Sneaker obj)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (obj.Id == 0)
                    {
                        _appDBContent.Sneakers.Add(obj);
                        await _appDBContent.SaveChangesAsync();
                    }
                    else
                    {
                        _appDBContent.Entry(obj).State = EntityState.Modified;
                        await _appDBContent.SaveChangesAsync();
                    }

                    return(RedirectToAction("SneakersList"));
                }
                return(View());
            }
            catch (Exception ex)
            {
                return(RedirectToAction("SneakersList"));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> Index(HoneyViewModel hvm)
        {
            ViewBag.Title = "Сбор продуктов";
            IEnumerable <Honey> hone = db.Honey.Where(i => i.Hive.Apiary.User.Email.Equals(User.Identity.Name) && i.Hive.Apiary.Id == hvm.Aid && i.Hive.Id == hvm.Hid).OrderByDescending(i => i.Date);

            hvm.Honeys = hone;
            Hive hiv = db.Hives.FirstOrDefault(i => i.Apiary.User.Email.Equals(User.Identity.Name) && i.Apiary.Id == hvm.Aid && i.Id == hvm.Hid);

            hvm.HiveName = hiv.Name;

            if (ModelState.IsValid)
            {
                Hive courseToUpdate = await db.Hives.FirstOrDefaultAsync(c => c.Apiary.Id == hvm.Aid && c.Id == hvm.Hid);

                db.Honey.Add(new Honey {
                    Prod = hvm.Prod, Get = hvm.Get, Date = hvm.Date, Hive = courseToUpdate
                });
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Honey", new { aid = hvm.Aid, hid = hvm.Hid }));
            }
            else
            {
                return(View(hvm));
            }
        }
Beispiel #4
0
        public async Task <bool> CreateCategory(Category category)
        {
            await _dBContent.Set <Category>().AddAsync(category);

            await _dBContent.SaveChangesAsync();

            return(true);
        }
        public async Task <IActionResult> Create([Bind("Id,Date,Text,User,UserCountry")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(comment));
        }
Beispiel #6
0
        public async Task <ActionResult <Bicycle> > PostBicycle([FromBody] Bicycle bicycle)
        {
            if (bicycle == null)
            {
                return(BadRequest());
            }

            db.Bicycle.Add(bicycle);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("GetBicycle", new { id = bicycle.id }, bicycle));
        }
        public async Task <IActionResult> EditAge(int id, User user)
        {
            if (id != user.UserId)
            {
                return(NotFound());
            }
            User newuser = await db.Users.FirstOrDefaultAsync(c => c.UserId == id);

            newuser.Age = user.Age;
            db.Update(newuser);
            await db.SaveChangesAsync();

            return(RedirectToAction("Details", "Profile", new { id = id }));
        }
        public async Task <IActionResult> SaveSite(Site site)
        {
            //TODO if site is null return or validation
            var category = _sitesCategory.AllCategories.FirstOrDefault(c => c.Id == site.CategoryId);
            var path     = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}";

            _content.Sites.Add(site);
            await _content.SaveChangesAsync();

            //return Redirect($"{path}/Home/Index");
            //return RedirectToAction("Index", "Home");
            //return View("~/Views/Home/Index.cshtml");
            return(View("../Home/Index", obj));
        }
Beispiel #9
0
        public async Task <IActionResult> CatCreate(CategoryCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                Category category1 = new Category {
                    CategoryName = model.CategoryName, Description = model.Description, Visible = model.Visible
                };
                db.Category.Add(category1);
                await db.SaveChangesAsync();

                return(RedirectToAction("CategoryList"));
            }
            return(View(model));
        }
Beispiel #10
0
        public async Task <ActionResult> CartAdd(int Id, int Quantity, string page)
        {
            User user = await _userManager.GetUserAsync(User);

            var cartTovar = await db.Tovar.FirstOrDefaultAsync(t => t.Id == Id);


            ShopCart shopCart = new ShopCart {
                UserId = user.Id, UserName = user.UserName, TovarId = cartTovar.Id, TovarName = cartTovar.TovarName, Price = cartTovar.Price, BuyQantity = Quantity, CatalogId = cartTovar.CatalogId
            };

            db.ShopCart.Add(shopCart);
            await db.SaveChangesAsync();

            return(RedirectToAction("Category", "Tovar", new { page }));
        }
Beispiel #11
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.UserName == model.UserName);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    user = new User(model.FirstName, model.LastName, model.UserName, model.Password)
                    {
                        Email       = model.Email,
                        PhoneNumber = model.Phone
                    };
                    Role userRole = await db.Roles.FirstOrDefaultAsync(r => r.Name == "user");

                    if (!(userRole is null))
                    {
                        user.Role = userRole;
                    }
                    db.Users.Add(user);
                    await db.SaveChangesAsync();

                    await Authenticate(user); // аутентификация

                    return(RedirectToAction("Index", "Conversations"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> Create(int id, DescCreateModel descriptions)
        {
            User Cuser = await _context.Users.FirstOrDefaultAsync(c => c.UserId == id);

            Descriptions desc = new Descriptions();

            desc.Description     = descriptions.Desc.Description;
            desc.UserCharacterId = Cuser;
            desc.UserAuthorId    = descriptions.UserAuthorId;

            _context.Add(desc);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index", "User"));
            //return Content(descriptions.UserAuthorId+ "      " + descriptions.Desc.Description + "      "   + id );
        }
Beispiel #13
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    // добавляем пользователя
                    db.Users.Add(new User {
                        Email = model.Email, Password = model.Password, Admin = "User"
                    });
                    await db.SaveChangesAsync();

                    await Authenticate(model.Email, "User"); // аутентификация

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _dbContext.User.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    user = new User {
                        Email = model.Email, Password = model.Password
                    };
                    Role userRole = await _dbContext.Role.FirstOrDefaultAsync(r => r.Name == "user");

                    if (userRole != null)
                    {
                        user.Role = userRole;
                    }

                    _dbContext.User.Add(user);

                    await _dbContext.SaveChangesAsync();

                    await Authenticate(user);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
Beispiel #15
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    db.Users.Add(new User {
                        Email = model.Email, Password = model.Password, Age = model.Age, Login = model.Login, Name = model.Name, Surname = model.Surname
                    });
                    await db.SaveChangesAsync();

                    //await Authenticate(user.Name, user.Surname, user.Email, user.Age, user.UserId); // аутентификация

                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
        public IActionResult Save(Site site)
        {
            var category = _sitesCategory.AllCategories.FirstOrDefault(c => c.Id == site.CategoryId);

            _content.Sites.Add(site);
            _content.SaveChangesAsync();
            return(Redirect("Index"));
        }
Beispiel #17
0
        public async Task <bool> CreateProduct(Product product)
        {
            var result = await _dBContent.Set <Product>().AddAsync(product);

            await _dBContent.SaveChangesAsync();

            return(true);
        }
Beispiel #18
0
        public async Task <IActionResult> Add(Merch merch)
        {
            _dbContext.Merch.Add(merch);
            await _dbContext.SaveChangesAsync();

            var merches = await _dbContext.Merch.ToListAsync();

            return(RedirectToAction("List"));
        }
Beispiel #19
0
        public async Task <IActionResult> Add(EventViewModel eventViewModel)
        {
            ViewBag.Title = "Добавление события";

            IEnumerable <Hive> hiv = db.Hives.Where(i => i.Apiary.Id == eventViewModel.Aid).OrderBy(i => i.Id);

            eventViewModel.Hives = hiv;



            if (ModelState.IsValid)
            {
                if (eventViewModel.Date < DateTime.Today)
                {
                    ModelState.AddModelError("", "Вы не можете выбрать дату в прошлом");
                    return(View(eventViewModel));
                }

                IEnumerable <Event> eves = db.Events.Where(i => i.Hive.Apiary.Id == eventViewModel.Aid && i.Hive.Name == eventViewModel.HiveName).OrderBy(i => i.Id);
                Event ev = eves.FirstOrDefault(i => i.Name == eventViewModel.Name && i.Date == eventViewModel.Date);


                if (ev == null)
                {
                    Hive courseToUpdate2 = await db.Hives.FirstOrDefaultAsync(c => c.Apiary.Id == eventViewModel.Aid && c.Name == eventViewModel.HiveName);

                    db.Events.Add(new Event {
                        Name = eventViewModel.Name, Desc = eventViewModel.Desc, Date = eventViewModel.Date, Hive = courseToUpdate2
                    });
                    await db.SaveChangesAsync();

                    return(RedirectToAction("HiveView", "Apiary", new { id = eventViewModel.Aid }));
                }
                else
                {
                    ModelState.AddModelError("", "Данное событие уже существует");
                    return(View(eventViewModel));
                }
            }
            else
            {
                return(View(eventViewModel));
            }
        }
Beispiel #20
0
        public async Task <IActionResult> Delete(int id)
        {
            IEnumerable <Apiary> api = _apiary.Apiaries.Where(i => i.User.Email.Equals(User.Identity.Name)).OrderBy(i => i.Id);
            Apiary apiar             = api.FirstOrDefault(i => i.Id == id);

            if (apiar == null)
            {
                return(RedirectToAction("", "Apiary"));
            }

            IEnumerable <Event> eve = db.Events.Where(i => i.Hive.Apiary.Id == id).OrderBy(i => i.Id);

            foreach (Event var in eve)
            {
                db.Events.Remove(var);
            }

            IEnumerable <Honey> hon = db.Honey.Where(i => i.Hive.Apiary.Id == id).OrderBy(i => i.Id);

            foreach (Honey dhon in hon)
            {
                db.Honey.Remove(dhon);
            }

            IEnumerable <Inspect> insp = db.Inspects.Where(i => i.Hive.Apiary.Id == id).OrderBy(i => i.Id);

            foreach (Inspect ins in insp)
            {
                db.Inspects.Remove(ins);
            }

            IEnumerable <Hive> hive = db.Hives.Where(i => i.Apiary.Id == id).OrderBy(i => i.Id);

            foreach (Hive var in hive)
            {
                db.Hives.Remove(var);
            }

            db.Apiaries.Remove(apiar);
            await db.SaveChangesAsync();

            return(RedirectToAction("", "Apiary"));
        }
        public async Task Create(Customer customer)
        {
            if (customer.Email == null || await GetByEmail(customer.Email) != null)
            {
                return;
            }
            await _appDBContent.Customer.AddAsync(customer);

            await _appDBContent.SaveChangesAsync();
        }
Beispiel #22
0
        public async Task createUser(RegisterViewModel user)
        {
            this.appDBContent.User.Add(new User {
                Name     = user.Name,
                Email    = user.Email,
                Password = user.Password,
                Login    = user.Login,
            });

            await appDBContent.SaveChangesAsync();
        }
        public async Task AddAsync(Order order)
        {
            order.OrderTime = DateTime.Now;
            await _appDBContent.Order.AddAsync(order);

            await _appDBContent.SaveChangesAsync();

            var items = _shopCart.ListShopItems;

            foreach (var item in items)
            {
                var orderDetails = new OrderDetail()
                {
                    ProductId = item.Product.Id,
                    OrderId   = order.Id
                };
                await _appDBContent.OrderDetail.AddAsync(orderDetails);
            }
            await _appDBContent.SaveChangesAsync();
        }
Beispiel #24
0
        public async Task CreateUser(RegisterViewModel user)
        {
            _appDBContent.User.Add(new User
            {
                GivenName    = user.GivenName,
                MiddleName   = user.MiddleName,
                Surname      = user.Surname,
                Email        = user.Email,
                PasswordHash = user.Password,
                Phone        = user.Phone,
            });

            await _appDBContent.SaveChangesAsync();
        }
Beispiel #25
0
        public async Task SendMessage(string message, string _id)

        {
            int     id       = Convert.ToInt32(_id);
            var     userName = Context.User.Identity.Name;
            Message mes      = new Message();

            mes.text = message;
            mes.date = DateTime.Now;
            mes.User = await _userManager.GetUserAsync(Context.User);

            mes.Thread = await db.Thread.FindAsync(id);

            db.Messages.Add(mes);
            await db.SaveChangesAsync();

            await Clients.All.SendAsync("ReceiveMessage", userName, message);
        }
        public async Task <IActionResult> DeleteOrder(int id)
        {
            try
            {
                var order = await _appDBContent.OrderDetail.FindAsync(id);

                if (order != null)
                {
                    _appDBContent.Remove(order);
                    await _appDBContent.SaveChangesAsync();
                }

                return(RedirectToAction("OrderList"));
            }
            catch (Exception e)
            {
                return(RedirectToAction("OrderList"));
            }
        }
Beispiel #27
0
        public async Task <IActionResult> New(CategoryListViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(model);

                var employee = new Category
                {
                    Name        = model.Name,
                    Description = model.Description,
                    Image       = uniqueFileName,
                };
                dbContext.Add(employee);
                await dbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Beispiel #28
0
        public async Task <ActionResult <Bike> > Put(int id, Bike model)
        {
            try
            {
                model.id = id;
                var oldBike = await _appDbContent.Bike.FirstOrDefaultAsync(x => x.id == id);

                if (oldBike == null)
                {
                    return(NotFound());
                }

                _appDbContent.Entry(oldBike).CurrentValues.SetValues(model);
                await _appDbContent.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception e)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, e.InnerException));
            }
        }
Beispiel #29
0
        public async Task <IActionResult> Edit(EditMatchViewModel model)
        {
            if (ModelState.IsValid)
            {
                Match match = await db.Match.FindAsync(model.id);

                if (match != null)
                {
                    match.name        = model.name;
                    match.team1       = model.team1;
                    match.team2       = model.team2;
                    match.scoresTeam1 = Convert.ToSByte(model.scoresTeam1);
                    match.scoresTeam2 = Convert.ToSByte(model.scoresTeam2);

                    await db.SaveChangesAsync();

                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }
        public async Task AddAsync(Product product)
        {
            await _appDBContent.Product.AddAsync(product);

            await _appDBContent.SaveChangesAsync();
        }