Пример #1
0
        public int CreateRecipe(RecipeCreate model)
        {
            using (var context = new CookbookContext())
            {
                var season = new Season()
                {
                    AuthorID = userId,
                    Summer = model.Season.Summer,
                    Fall = model.Season.Fall,
                    Winter = model.Season.Winter,
                    Spring = model.Season.Spring
                };

                context.Seasons.Add(season);
                context.SaveChanges();

                var entity = new Recipe()
                {
                    AuthorID = userId,
                    Name = model.Name,
                    SeasonID = season.ID,
                    Description = model.Description,
                    DateCreated = DateTimeOffset.UtcNow,
                };

                context.Recipes.Add(entity);
                context.SaveChanges();
                return entity.ID;
            }
        }
Пример #2
0
        public void Add(Ingredient entityToAdd)
        {
            var recipe =
                _cookbookContext.Recipe.SingleOrDefault(r => r.Id == entityToAdd.RelRecipeIngredient.First().RecipeId);

            if (recipe == null)
            {
                throw new InvalidOperationException();
            }

            // check if Ingredient already exists
            var ingredient = _cookbookContext.Ingredient.SingleOrDefault(i => i.Name == entityToAdd.Name);

            if (ingredient == null)
            {
                ingredient = new Ingredient {
                    Name = entityToAdd.Name
                };
                _cookbookContext.Ingredient.Add(ingredient);
                _cookbookContext.SaveChanges();
            }

            // save RelRecipeIngredient
            _cookbookContext.RelRecipeIngredient.Add(new RelRecipeIngredient {
                RecipeId = recipe.Id, IngredientId = ingredient.Id
            });
            _cookbookContext.SaveChanges();
        }
Пример #3
0
        public Model.Dokument Insert(DokumentUpsertRequest request)
        {
            var entity = _mapper.Map <Database.Dokument>(request);

            _context.Dokumenti.Add(entity);
            _context.SaveChanges();
            return(_mapper.Map <Model.Dokument>(entity));
        }
        public void Delete(int id)
        {
            var cookBookItemToRemove = this.GetById(id);

            if (cookBookItemToRemove != null)
            {
                _dbContext.CookBookItems.Remove(cookBookItemToRemove);
                _dbContext.SaveChanges();
            }
        }
        public void Delete(int id)
        {
            var descriptionToRemove = this.GetById(id);

            if (descriptionToRemove != null)
            {
                _dbContext.Descriptions.Remove(descriptionToRemove);
                _dbContext.SaveChanges();
            }
        }
Пример #6
0
        public void Delete(int id)
        {
            var ingredientToRemove = this.GetById(id);

            if (ingredientToRemove != null)
            {
                _dbContext.Ingredients.Remove(ingredientToRemove);
                _dbContext.SaveChanges();
            }
        }
        public Model.Korisnik Insert(KorisnikInsertRequest request)
        {
            var entity = _mapper.Map <Database.Korisnik>(request);

            if (request.Password != request.PasswordPotvrda)
            {
                throw new Exception("Passwordi se ne slažu");
            }

            entity.LozinkaSalt = GenerateSalt();
            entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password);

            _context.Korisnik.Add(entity);
            _context.SaveChanges();

            if (request.Uloge.Count() > 0)
            {
                foreach (var uloga in request.Uloge)
                {
                    Database.KorisnikUloga korisniciUloge = new Database.KorisnikUloga();
                    korisniciUloge.KorisnikId   = entity.KorisnikId;
                    korisniciUloge.UlogaId      = uloga;
                    korisniciUloge.DatumIzmjene = DateTime.Now;
                    _context.KorisnikUloga.Add(korisniciUloge);
                }
            }
            else
            {
                Database.KorisnikUloga korisniciUloge = new Database.KorisnikUloga();
                korisniciUloge.KorisnikId   = entity.KorisnikId;
                korisniciUloge.UlogaId      = request.Uloga;
                korisniciUloge.DatumIzmjene = DateTime.Now;
                _context.KorisnikUloga.Add(korisniciUloge);
            }
            _context.SaveChanges();
            // -------- dodano posebno
            var korisnik = new Model.Korisnik()
            {
                Ime           = entity.Ime,
                Prezime       = entity.Prezime,
                KorisnickoIme = entity.KorisnickoIme,
                Email         = entity.Email,
                Telefon       = entity.Telefon,
                KorisnikId    = entity.KorisnikId
            };

            //-----


            // return _mapper.Map<Model.Korisnici>(entity);
            return(korisnik);
        }
        public void Delete(int id)
        {
            var recipeToRemove = _dbContext.Recipes.Where(e => e.Id == id)
                                 .Include(e => e.CookBookItems)
                                 .Include(e => e.Description)
                                 .First();

            if (recipeToRemove != null)
            {
                _dbContext.Remove(recipeToRemove);
                _dbContext.SaveChanges();
            }
        }
        public Model.Posjetilac Insert(PosjetilacUpsertRequest request)
        {
            var entity = _mapper.Map <Database.Posjetilac>(request);

            _context.Posjetilac.Add(entity);
            _context.SaveChanges();
            return(_mapper.Map <Model.Posjetilac>(entity));

            //if (request.Password != request.PasswordPotvrda)
            //{
            //    throw new Exception("Passwordi se ne slažu");
            //}

            //entity.LozinkaSalt = GenerateSalt();
            //entity.LozinkaHash = GenerateHash(entity.LozinkaSalt, request.Password);

            //_context.Korisnik.Add(entity);
            //_context.SaveChanges();

            // -------- dodano posebno
            //var kupac = new Model.Korisnik()
            //{
            //    Ime = request.Ime,
            //    Prezime = request.Prezime,
            //    KorisnickoIme = request.KorisnickoIme,
            //    Email = request.Email,
            //    Telefon = request.Telefon
            //};
            ////-----
            //_context.SaveChanges();

            //var entity1 = _mapper.Map<Database.Posjetilac>(request);
            //entity1.KorisnikId = entity.KorisnikId;
            //entity1.DatumRegistracije = DateTime.Now;

            //_context.Posjetilac.Add(entity1);
            //_context.SaveChanges();

            //var entity2 = _mapper.Map<Database.KorisnikUloga>(request);
            //entity2.KorisnikId = entity.KorisnikId;
            //entity2.UlogaId = 2;
            //entity2.DatumIzmjene = DateTime.Now;

            //_context.KorisnikUloga.Add(entity2);
            //_context.SaveChanges();
            // return _mapper.Map<Model.Kupac>(entity);
        }
Пример #10
0
        public int CreateLarder(LarderCreate model)
        {
            using (var context = new CookbookContext())
            {
                var season = new Season();
                if (model.Season == null)
                {
                    season.AuthorID = userId;
                    season.Summer   = false;
                    season.Fall     = false;
                    season.Winter   = false;
                    season.Spring   = false;
                }
                else
                {
                    season.AuthorID = userId;
                    season.Summer   = model.Season.Summer;
                    season.Fall     = model.Season.Fall;
                    season.Winter   = model.Season.Winter;
                    season.Spring   = model.Season.Spring;
                };

                context.Seasons.Add(season);
                context.SaveChanges();

                var entity = new LarderModel()
                {
                    AuthorID    = userId,
                    Name        = model.Name,
                    SeasonID    = season.ID,
                    Description = model.Description,
                    DateCreated = DateTimeOffset.UtcNow,
                };

                context.Larders.Add(entity);
                context.SaveChanges();
                return(entity.ID);
            }
        }
Пример #11
0
        public bool UpdateAction(ActionEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Actions
                    .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Description = model.Description;

                return(context.SaveChanges() == 1);
            }
        }
Пример #12
0
        public bool DeleteLarder(int id)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Larders
                    .Single(e => e.ID == id && e.AuthorID == userId);
                context.Larders.Remove(entity);

                return(context.SaveChanges() == 1);
            }
        }
Пример #13
0
        public bool UpdateLarder(LarderEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Larders
                    .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Name         = model.Name;
                entity.Description  = model.Description;
                entity.DateModified = DateTimeOffset.UtcNow;

                return(context.SaveChanges() == 1);
            }
        }
Пример #14
0
        public bool CreateAction(ActionCreate model)
        {
            var entity = new Data.Models.Action()
            {
                AuthorID    = userId,
                Description = model.Description,
                LarderId    = model.LarderID
            };

            using (var context = new CookbookContext())
            {
                context.Actions.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
Пример #15
0
        public bool CreateLarder(LarderCreate model)
        {
            var entity = new LarderModel()
            {
                AuthorID    = userId,
                Name        = model.Name,
                Description = model.Description,
                DateCreated = DateTimeOffset.UtcNow,
            };

            using (var context = new CookbookContext())
            {
                context.Larders.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
Пример #16
0
        public async Task <ActionResult> Create(Recipe recipe, int TagId)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            recipe.User = currentUser;
            _db.Recipes.Add(recipe);
            if (TagId != 0)
            {
                _db.RecipeTag.Add(new RecipeTag()
                {
                    RecipeId = recipe.RecipeId, TagId = TagId
                });
            }
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #17
0
        public bool UpdateIngredient(IngredientEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                    .Ingredients
                    .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Name         = model.Name;
                entity.Description  = model.Description;
                entity.Amount       = model.Amount;
                entity.Unit         = model.Unit;
                entity.DateModified = DateTimeOffset.UtcNow;

                return(context.SaveChanges() == 1);
            }
        }
Пример #18
0
        public bool CreateIngredient(IngredientCreate model)
        {
            var entity = new Ingredient()
            {
                AuthorID    = userId,
                Name        = model.Name,
                Description = model.Description,
                DateCreated = DateTimeOffset.UtcNow,
                Amount      = model.Amount,
                Unit        = model.Unit,
                LarderId    = model.LarderId,
            };

            using (var context = new CookbookContext())
            {
                context.Ingredients.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
Пример #19
0
        public bool UpdateRecipe(RecipeEdit model)
        {
            using (var context = new CookbookContext())
            {
                var entity =
                    context
                           .Recipes
                           .Single(e => e.ID == model.ID && e.AuthorID == userId);
                entity.Name = model.Name;
                entity.Description = model.Description;
                entity.DateModified = DateTimeOffset.UtcNow;
                if (model.Season.Fall) { entity.Season.Fall = true;} else { entity.Season.Fall = false; }
                if (model.Season.Spring) { entity.Season.Spring = true;} else { entity.Season.Spring = false; }
                if (model.Season.Summer) { entity.Season.Summer = true;} else { entity.Season.Summer = false; }
                if (model.Season.Winter) { entity.Season.Winter = true;} else { entity.Season.Winter = false; }

                return context.SaveChanges() != 0;
            }
        }
Пример #20
0
 public bool AddPlating(PlatingAddList model)
 {
     using (var context = new CookbookContext())
     {
         var entities = context.RecipePlatings.Where(e => e.RecipeID == model.RecipeId);
         foreach (var entity in entities)
         {
             context.RecipePlatings.Remove(entity);
         }
         foreach (var plating in model.Platings)
         {
             if (plating.IsIncluded == true)
             {
                 context.Set <RecipePlating>().Add(new RecipePlating
                 {
                     PlatingID = plating.ID,
                     RecipeID  = model.RecipeId
                 });
             }
         }
         return(context.SaveChanges() != -1);
     }
 }
Пример #21
0
 public void Add(Recipe entity)
 {
     _cookbookContext.Recipe.Add(entity);
     _cookbookContext.SaveChanges();
 }
Пример #22
0
 public void Add(User entity)
 {
     _cookbookContext.User.Add(entity);
     _cookbookContext.SaveChanges();
 }