Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Body,Raiting,PublishDate,AppId,UserNameId")] Review review)
        {
            if (id != review.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    review.PublishDate = DateTime.Now;
                    _context.Update(review);
                    float sum = 0;
                    foreach (var item in _context.Review)
                    {
                        if (item.AppId == review.AppId)
                        {
                            sum += item.Raiting;
                        }
                    }
                    foreach (var item in _context.Apps) //updating the average raiting of the app
                    {
                        if (item.Id == review.AppId)
                        {
                            item.AverageRaiting = sum / item.countReview;
                            _context.Update(item);
                            break;
                        }
                    }

                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ReviewExists(review.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AppId"]      = new SelectList(_context.Apps, "Id", "Name", review.AppId);
            ViewData["UserNameId"] = new SelectList(_context.User, "Id", "Name", review.UserNameId);
            return(View(review));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Video,AppId")] AppVideo appVideo)
        {
            if (id != appVideo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(appVideo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppVideoExists(appVideo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AppId"] = new SelectList(_context.Apps, "Id", "DeveloperName", appVideo.AppId);
            return(View(appVideo));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Email,Password,UserType")] User user)
        {
            if (id != user.Id)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("HomePage", "Apps"));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(View(user));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Image,AppsId")] Logo logo)
        {
            if (id != logo.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(logo);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LogoExists(logo.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["AppsId"] = new SelectList(_context.Apps, "Id", "Name", logo.AppsId);
            return(View(logo));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] Category category)
        {
            if (id != category.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,NameOnCard,CardNumber,ExpiredDate,CVV,IdNumber")] PaymentMethod paymentMethod)
        {
            if (id != paymentMethod.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(paymentMethod);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentMethodExists(paymentMethod.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(paymentMethod));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,Description,publishDate,Logo,CategoryId,Size,AverageRaiting," +
                                                             "countReview, DeveloperName")] App app)
        {
            app.publishDate = DateTime.Now;

            foreach (var item in _context.Logo)
            {
                if (item.AppsId == app.Id)
                {
                    item.Image = app.Logo.Image;
                    _context.Update(item);
                    app.Logo = item;
                    break;
                }
            }
            await _context.SaveChangesAsync();

            if (id != app.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(app);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppExists(app.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Name", app.CategoryId);
            return(View(app));
        }
Ejemplo n.º 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));
        }