public async Task <IHttpActionResult> PutAlbum(int id, Album album)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != album.AlbumId)
            {
                return(BadRequest());
            }

            db.Entry(album).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AlbumExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        // GET: /ShoppingCart/AddToCart/5
        public async Task <ActionResult> AddToCart(int id)
        {
            var cart = ShoppingCart.GetCart(_storeContext, this);

            await cart.AddToCart(await _storeContext.Albums.SingleAsync(a => a.AlbumId == id));

            await _storeContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        // GET: /ShoppingCart/AddToCart/5
        public async Task <ActionResult> AddToCart(int id)
        {
            var cart = ShoppingCart.GetCart(_storeContext, this);

            await cart.AddToCart(await _storeContext.Albums.SingleAsync(a => a.AlbumId == id));

            await _storeContext.SaveChangesAsync();

            _logger.Info("Adding an item to shopping cart (album id: {0})", id);

            return(RedirectToAction("Index"));
        }
Esempio n. 4
0
        // GET: /ShoppingCart/AddToCart/5
        public async Task <ActionResult> AddToCart(int id)
        {
            _logger.Debug("/ShoppingCart/AddToCart/ called with id: {0}", id);

            var cart = ShoppingCart.GetCart(_storeContext, this);

            await cart.AddToCart(await _storeContext.Albums.SingleAsync(a => a.AlbumId == id));

            await _storeContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Create(Album album)
        {
            if (ModelState.IsValid)
            {
                _storeContext.Albums.Add(album);

                await _storeContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(await BuildView(album));
        }
Esempio n. 6
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Name,Description, Enabled")] Models.FeatureToggle featureToggle)
        {
            if (ModelState.IsValid)
            {
                featureToggle.Id = Guid.NewGuid();
                db.FeatureToggles.Add(featureToggle);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(featureToggle));
        }
Esempio n. 7
0
        // GET: /ShoppingCart/AddToCart/5
        public async Task <ActionResult> AddToCart(int id)
        {
            var cart = ShoppingCart.GetCart(_storeContext, this);

            await cart.AddToCart(await _storeContext.Albums.SingleAsync(a => a.AlbumId == id));

            await _storeContext.SaveChangesAsync();

            throw new System.Exception();  //for test
            counterHelper.Increment(Counters.AddsToCart);

            return(RedirectToAction("Index"));
        }
        // GET: /ShoppingCart/AddToCart/5
        public async Task <ActionResult> AddToCart(int id)
        {
            var cart = ShoppingCart.GetCart(_storeContext, this);

            var album = await _storeContext.Albums.SingleAsync(a => a.AlbumId == id);

            await cart.AddToCart(album);

            _logger.Info($"Album name: {album.Title}. Album was added.");

            await _storeContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        // GET: /ShoppingCart/AddToCart/5
        public async Task <ActionResult> AddToCart(int id)
        {
            var cart = ShoppingCart.GetCart(_storeContext, this);

            await cart.AddToCart(await _storeContext.Albums.SingleAsync(a => a.AlbumId == id));

            await _storeContext.SaveChangesAsync();

            _logger.Info($"Item \"{_storeContext.Albums.Single(a => a.AlbumId == id).Title}\" was added to cart");

            counter.Increment(Counters.ItemsInCard);

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Create(Album album)
        {
            _logger.Info("StoreManagerController Create method");
            if (ModelState.IsValid)
            {
                _storeContext.Albums.Add(album);

                await _storeContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(await BuildView(album));
        }
        public async Task <ActionResult> Create(Album album)
        {
            if (ModelState.IsValid)
            {
                _storeContext.Albums.Add(album);

                await _storeContext.SaveChangesAsync();

                logger.Info($"Created new album with title: {album.Title}");

                return(RedirectToAction("Index"));
            }

            return(await BuildView(album));
        }
        // GET: /ShoppingCart/AddToCart/5
        public async Task <ActionResult> AddToCart(int id)
        {
        #if DEBUG
            _logger?.Debug($"AddToCart action of controller {this.GetType().Name} invoked");
        #endif

            var cart = ShoppingCart.GetCart(_storeContext, this);

            await cart.AddToCart(await _storeContext.Albums.SingleAsync(a => a.AlbumId == id));

            await _storeContext.SaveChangesAsync();

            _logger?.Info($"Album with id {id} added to cart. Cart count equals {await cart.GetCount()}");

            return(RedirectToAction("Index"));
        }
Esempio n. 13
0
        public async Task <ActionResult> AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            if (ModelState.IsValid &&
                string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase))
            {
                order.Username  = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                _storeContext.Orders.Add(order);

                await ShoppingCart.GetCart(_storeContext, this).CreateOrder(order);

                await _storeContext.SaveChangesAsync();

                _logger.Info("AddressAndPayment success (order id: {0})", order.OrderId);

                return(RedirectToAction("Complete", new { id = order.OrderId }));
            }

            _logger.Warn("AddressAndPayment errors (order id: {0})", order.OrderId);

            return(View(order));
        }
Esempio n. 14
0
        public async Task <ActionResult> AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            if (ModelState.IsValid &&
                string.Equals(values["PromoCode"], PromoCode, StringComparison.OrdinalIgnoreCase))
            {
                order.Username  = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                _storeContext.Orders.Add(order);

                await ShoppingCart.GetCart(_storeContext, this).CreateOrder(order);

                await _storeContext.SaveChangesAsync();

                PerformanceHelper.IncrementCounter(MusicStorePerformanceConstants.PaymentsCounterName);

                return(RedirectToAction("Complete", new { id = order.OrderId }));
            }

            return(View(order));
        }
Esempio n. 15
0
        public async Task <ActionResult> Create(Album album)
        {
            if (ModelState.IsValid)
            {
                _storeContext.Albums.Add(album);

                await _storeContext.SaveChangesAsync();

                _logger.Info("Create album (id: {0}, user: {1})", album.AlbumId, User.Identity.Name);

                return(RedirectToAction("Index"));
            }

            _logger.Warn("Errors when creating album (id: {0}, user: {1})", album.AlbumId, User.Identity.Name);

            return(await BuildView(album));
        }
Esempio n. 16
0
        private void SetValue(bool toggleValue)
        {
            MusicStoreEntities db = new MusicStoreEntities();
            var featureToggle     = db.FeatureToggles.FindAsync(_id).Result;

            featureToggle.Enabled         = toggleValue;
            db.Entry(featureToggle).State = EntityState.Modified;
            db.SaveChangesAsync();
        }
Esempio n. 17
0
        public async Task <ActionResult> Upload([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album, int id, HttpPostedFileBase file)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    album.AlbumId = id;

                    if (file.ContentLength > 0)
                    {
                        //只是存資料夾
                        var fileName = Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/App_Data/Images"), fileName);
                        file.SaveAs(path);

                        //建立容器
                        //this.CreateContainerExists();

                        //HttpPostedFileBase轉成byte
                        //MemoryStream target = new MemoryStream();
                        //file.InputStream.CopyTo(target);
                        //byte[] data = target.ToArray();
                        //SaveImage(Guid.NewGuid().ToString(), file.FileName, file.ContentType, data);
                        //SaveImage(file);

                        //album.AlbumArtUrl = "https://wecaremvc.blob.core.windows.net/photos/" + file.FileName;
                        album.AlbumArtUrl = path;

                        db.Entry(album).State = EntityState.Modified;
                        await db.SaveChangesAsync();
                    }
                }
                //ViewBag.Message = "Upload successful";
                return(RedirectToAction("Index"));
            }
            catch
            {
                ViewBag.Message = "Upload failed";
                //return RedirectToAction("Uploads");
                ViewBag.ArtistId = new SelectList(db.Artists, "ArtistId", "Name", album.ArtistId);
                ViewBag.GenreId  = new SelectList(db.Genres, "GenreId", "Name", album.GenreId);
                return(View(album));
            }
        }
Esempio n. 18
0
        public async Task <ActionResult> AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            if (ModelState.IsValid)
            {
                order.Username  = User.Identity.Name;
                order.OrderDate = DateTime.Now;

                _storeContext.Orders.Add(order);

                await ShoppingCart.GetCart(_storeContext, HttpContext.User.Identity.Name).CreateOrder(order);

                await _storeContext.SaveChangesAsync();

                return(RedirectToAction("Complete", new { id = order.OrderId }));
            }

            return(View(order));
        }