Beispiel #1
0
 public ActionResult <Record> Get(int id)
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         return(context.Records.First(b => b.Id == id));
     }
 }
 public IActionResult Post([FromBody] Genre newGenres)
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         context.Genres.Add(newGenres);
         context.SaveChanges();
     }
     return(Created("/Genres", newGenres));
 }
Beispiel #3
0
 public IActionResult Post([FromBody] User newUser)
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         context.Users.Add(newUser);
         context.SaveChanges();
     }
     return(Created("/User", newUser));
 }
Beispiel #4
0
 public ActionResult <User> Get(int id)
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         return(context.Users
                .Include(user => user.Orders)
                .First(b => b.Id == id));
     }
 }
Beispiel #5
0
 public IActionResult Delete(int id)
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         Record toRemove = context.Records.First(u => u.Id == id);
         context.Records.Remove(toRemove);
         context.SaveChanges();
     }
     return(Ok());
 }
 public IEnumerable <Order> Get()
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         return(context.Orders
                .Include(order => order.Cart)
                .ThenInclude(cart => cart.Record)
                .ToList());
     }
 }
 public IActionResult Delete(int id)
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         Genre RemoveGenres = context.Genres.First(u => u.Id == id);
         context.Genres.Remove(RemoveGenres);
         context.SaveChanges();
     }
     return(Ok());
 }
 public ActionResult <Genre> Get(int id)
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         return(context.Genres
                .Include(genre => genre.ProductsInGenre)
                .ThenInclude(pig => pig.Record)
                .First(b => b.Id == id));
     }
 }
Beispiel #9
0
 public IActionResult Delete(int id)
 {
     using (RecordStoreContexts context = new RecordStoreContexts())
     {
         User RemoveUser = context.Users.First(u => u.Id == id);
         context.Users.Remove(RemoveUser);
         context.SaveChanges();
     }
     return(Ok());
 }
        public IActionResult Put(int id, [FromBody] Genre newGenres)
        {
            //valideringtest
            using (RecordStoreContexts context = new RecordStoreContexts())
            {
                Genre toUpdate = context.Genres.First(u => u.Id == id);
                toUpdate.Name = newGenres.Name;

                context.SaveChanges();
            }
            return(Ok());
        }
Beispiel #11
0
        public IEnumerable <RecordViewModel> Get()
        {
            using (RecordStoreContexts context = new RecordStoreContexts())
            {
                List <Record> records = context.Records
                                        .Include(records => records.ProductsInGenre)
                                        .ThenInclude(ProductsInGenre => ProductsInGenre.Genre)
                                        .ToList();

                List <RecordViewModel> viewModels = _mapper.Map <List <RecordViewModel> >(records);

                return(viewModels);
            }
        }
Beispiel #12
0
        public IActionResult Put(int id, [FromBody] User newUser)
        {
            //valideringtest
            using (RecordStoreContexts context = new RecordStoreContexts())
            {
                User toUpdate = context.Users.First(u => u.Id == id);
                toUpdate.FirstName = newUser.FirstName;
                toUpdate.LastName  = newUser.LastName;
                toUpdate.Email     = newUser.Email;

                context.SaveChanges();
            }
            return(Ok());
        }
Beispiel #13
0
        public IActionResult Post([FromBody] RecordViewModel newRecord)
        {
            Record record = _mapper.Map <Record>(newRecord);


            foreach (ProductsInGenre ProductsInGenre in record.ProductsInGenre)
            {
                ProductsInGenre.Genre = null;
            }

            using (RecordStoreContexts context = new RecordStoreContexts())
            {
                context.Records.Add(record);
                context.SaveChanges();
            }
            return(Created("/Record", record));
        }
Beispiel #14
0
        public IActionResult Put(int id, [FromBody] Record newRecord)
        {
            //validering

            using (RecordStoreContexts context = new RecordStoreContexts())
            {
                Record toUpdate = context.Records.First(u => u.Id == id);
                toUpdate.Artist = newRecord.Artist;
                toUpdate.Album  = newRecord.Album;
                toUpdate.Image  = newRecord.Image;
                toUpdate.Info   = newRecord.Info;
                toUpdate.Price  = newRecord.Price;

                context.SaveChanges();
            }
            return(Ok());
        }
        public IActionResult Post([FromBody] OrderViewModel newOrder)
        {
            Order order = _mapper.Map <Order>(newOrder);

            using (RecordStoreContexts context = new RecordStoreContexts())
            {
                User userExists = context.Users.FirstOrDefault(User => User.Email == newOrder.Email);

                int userId = 0;
                if (userExists == null)
                {
                    User u = new User();
                    u.FirstName = newOrder.FirstName;
                    u.LastName  = newOrder.LastName;
                    u.Email     = newOrder.Email;
                    context.Users.Add(u);
                    context.SaveChanges();
                    userId = u.Id;
                }
                else
                {
                    userId = userExists.Id;
                }


                Order o = new Order();
                o.Created = DateTime.Now;
                o.UserId  = userId;
                context.Orders.Add(o);
                context.SaveChanges();

                foreach (Cart cart in order.Cart)
                {
                    Cart c = new Cart();
                    c.RecordId = cart.RecordId;
                    c.OrderId  = o.Id;
                    context.Carts.Add(c);

                    context.SaveChanges();
                }

                return(Created("/Order", o));
            }
        }