コード例 #1
0
        public async Task <IActionResult> Create([Bind("Id,Title,Body,Raiting,PublishDate,AppId,UserNameId")] Review review, string userName)
        {
            if (ModelState.IsValid)
            {
                review.Id = 0;
                foreach (var item in _context.Apps)
                {
                    if (item.Id == review.AppId)
                    { //updating the app's new avg raiting
                        item.AverageRaiting = ((item.AverageRaiting * item.countReview) + review.Raiting) / (item.countReview + 1);
                        item.countReview++;
                        break;
                    }
                }
                foreach (var item in _context.User)
                {
                    if (userName.Equals(item.Name))
                    { //updating the review's user info
                        review.UserName   = item;
                        review.UserNameId = item.Id;
                        break;
                    }
                }
                review.PublishDate = DateTime.Now;

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

                return(Redirect("/Apps/Details/" + review.AppId));
            }

            ViewData["AppId"]      = new SelectList(_context.Apps, "Id", "Name", review.AppId);
            ViewData["UserNameId"] = new SelectList(_context.User, "Id", "Name", review.UserNameId);
            return(View(review));
        }
コード例 #2
0
        public async Task <IActionResult> Register([Bind("Id,Name,Email,Password,UserType")] User user)
        {
            if (ModelState.IsValid)
            {
                var q = _context.User.FirstOrDefault(u => u.Email == user.Email || u.Name == user.Name);

                if (q == null)
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    var u = _context.User.FirstOrDefault(u => u.Email == user.Email && u.Password == user.Password);
                    Signin(u);


                    return(RedirectToAction("HomePage", "Apps"));
                }
                else
                {
                    ViewData["Error"] = "Unable to comply, cannot register this user.";
                }
            }

            return(View(user));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,Image,AppsId")] Logo logo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(logo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AppsId"] = new SelectList(_context.Apps, "Id", "Name", logo.AppsId);
            return(View(logo));
        }
コード例 #4
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Description,publishDate,Logo,CategoryId,Size," +
                                                       "AverageRaiting,countReview,DeveloperName,Images")] App app, int[] Images, int[] Videos)
        {
            if (ModelState.IsValid)
            {
                Logo log = new Logo();
                log.Image  = app.Logo.Image;
                log.Apps   = app;
                log.AppsId = app.Id;
                _context.Add(log);

                app.publishDate = DateTime.Now;
                app.Logo        = log;

                app.Images = new List <AppImage>();
                app.Images.AddRange(_context.AppsImage.Where(x => Images.Contains(x.Id)));
                foreach (var item in app.Images)
                {
                    item.AppId = app.Id;
                    item.App   = app;
                }

                app.Videos = new List <AppVideo>();
                app.Videos.AddRange(_context.AppVideo.Where(x => Videos.Contains(x.Id)));
                foreach (var item in app.Videos)
                {
                    item.AppId = app.Id;
                    item.App   = app;
                }

                _context.Add(app);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", app.CategoryId);
            return(View(app));
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            Console.WriteLine(ModelState.Values);

            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Name,Video")] AppVideo appVideo)
        {
            if (ModelState.IsValid)
            {
                appVideo.AppId = 1; //default before change in app's create
                _context.Add(appVideo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["AppId"] = new SelectList(_context.Apps, "Id", "Name");

            return(View(appVideo));
        }
コード例 #7
0
        public async Task <IActionResult> Create([Bind("Id,NameOnCard,CardNumber,ExpiredDate,CVV,IdNumber")] PaymentMethod paymentMethod, int[] Users)
        {
            if (ModelState.IsValid)
            {
                paymentMethod.Users = new List <User>();
                var usr = _context.User.Include(u => u.PaymentMethods).Include(u => u.AppListUser);

                foreach (var item in usr)
                {
                    if (Users.Contains(item.Id)) //update user list depend on which users can use the payment method
                    {
                        paymentMethod.Users.Add(item);
                    }
                }

                _context.Add(paymentMethod);
                await _context.SaveChangesAsync();
            }
            return(RedirectToAction("HomePage", "Apps"));
        }
コード例 #8
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,City,PaymentMethodId,AppId")] Payment payment, string userName)
        {
            if (ModelState.IsValid)
            {
                App purchasedApp = null;
                foreach (var item in _context.Apps)
                {
                    if (item.Id == payment.AppId)
                    {
                        purchasedApp = item;
                        break;
                    }
                }

                var usr = _context.User.Include(u => u.PaymentMethods).Include(u => u.AppListUser);
                foreach (var item in usr)
                {
                    if (item.Name.Equals(userName))
                    {
                        if (item.AppListUser == null)
                        {
                            item.AppListUser = new List <App>();
                        }
                        item.AppListUser.Add(purchasedApp);
                        _context.Update(item);
                        break;
                    }
                }

                payment.Id = 0; //be updated after added to DB
                _context.Add(payment);
                await _context.SaveChangesAsync();

                return(RedirectToAction("HomePage", "Apps"));
            }
            ViewData["AppId"] = new SelectList(_context.Apps, "Id", "Name", payment.AppId);

            return(View(payment));
        }