示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nazwa,Hasztag,Ocena,Tresc,KategoriaId")] Przepis przepis)
        {
            if (id != przepis.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(przepis);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PrzepisExists(przepis.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KategoriaId"] = new SelectList(_context.Kategorie, "Id", "Nazwa", przepis.Nazwa); //zmiana
            return(View(przepis));
        }
        public IHttpActionResult PutPrzepis(int id, Przepis przepis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != przepis.idPrzepis)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PrzepisExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task<IActionResult> Edit(int id, [Bind("Id,Nazwa,Hasztag,Ocena,Image,Tresc,KategoriaId")] Przepis przepis, List<IFormFile> Image)
        {
            if (id != przepis.Id)
            {
                return NotFound();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    foreach (var item in Image)
                    {
                        if (item.Length > 0)
                        {
                            using (var stream = new MemoryStream())
                            {
                                await item.CopyToAsync(stream);
                                przepis.Image = stream.ToArray();
                            }
                        } else
                        {
                            var przepisEdytowany = await _context.Przepisy.FindAsync(id);
                            przepis.Image = przepisEdytowany.Image; 
                        }
                    }  
                }
                    _context.Update(przepis);
                    await _context.SaveChangesAsync();
                }
示例#4
0
        public async Task <IActionResult> PutPrzepis([FromRoute] int id, [FromBody] Przepis przepis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != przepis.Id)
            {
                return(BadRequest());
            }

            _context.Entry(przepis).State = EntityState.Modified;

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

            return(NoContent());
        }
示例#5
0
        public IActionResult Create(Przepis newRecipe)
        {
            _context.Przepis.Add(newRecipe);
            _context.SaveChanges();

            return(StatusCode(201, newRecipe));
        }
        public ActionResult Deletep(int id, FormCollection collection)
        {
            Przepis przepis = db.Przepisy.Find(id);

            db.Przepisy.Remove(przepis);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Editp(int id, Przepis przepis)
 {
     if (ModelState.IsValid)
     {
         db.Entry(przepis).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(przepis));
 }
示例#8
0
        public ActionResult AddCom(int id)
        {
            Przepis przepis    = db.Przepisy.Find(id);
            var     komentarze = db.Komentarze.ToList();
            var     vm         = new ViewModels()
            {
                Komentarze = komentarze.Where(x => x.PrzepisID == przepis.PrzepisID)
            };

            return(View(vm));
        }
        public async Task <IActionResult> OnGetAsync(int id)
        {
            Przepis = await _baza.Przepis.FindAsync(id);

            if (Przepis == null)
            {
                return(RedirectToPage("/Index"));
            }

            return(Page());
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("Id,Nazwa,Hasztag,Ocena,Tresc,KategoriaId")] Przepis przepis)
        {
            if (ModelState.IsValid)
            {
                _context.Add(przepis);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["KategoriaId"] = new SelectList(_context.Kategorie, "Id", "Nazwa", przepis.Nazwa); //zmienilam z przepis.KategoriaId na Nazwa
            return(View(przepis));
        }
示例#11
0
        public async Task OnGetAsync(int id)
        {
            if (id == 0)
            {
                id = numer.numerprzepis;
            }

            Przepis   = _baza.Przepis.Find(id);
            Komentarz = await _baza.Komentarze.Where(x => x.Id_Przepisu.ToString().Contains(id.ToString())).ToListAsync();

            numer.numerprzepis = id;
        }
        public IHttpActionResult PostPrzepis(Przepis przepis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Przepis.Add(przepis);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = przepis.idPrzepis }, przepis));
        }
示例#13
0
        public async Task <IActionResult> PostPrzepis([FromBody] Przepis przepis)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.PrzepisyOdwiedziny.Add(przepis);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPrzepis", new { id = przepis.Id }, przepis));
        }
        public IHttpActionResult DeletePrzepis(int id)
        {
            Przepis przepis = db.Przepis.Find(id);

            if (przepis == null)
            {
                return(NotFound());
            }

            db.Przepis.Remove(przepis);
            db.SaveChanges();

            return(Ok(przepis));
        }
示例#15
0
        public ActionResult Editp(int id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Przepis przepis = db.Przepisy.Find(id);

            if (przepis == null)
            {
                return(HttpNotFound());
            }
            return(View(przepis));
        }
示例#16
0
        public IActionResult Update(Przepis updatedRecipe)
        {
            var c = _context.Przepis.FirstOrDefault(e => e.IdPrzepisu == updatedRecipe.IdPrzepisu);

            if (c == null)
            {
                return(NotFound());
            }
            _context.Przepis.Attach(updatedRecipe);
            _context.Entry(updatedRecipe).State = EntityState.Modified;
            _context.SaveChanges();

            return(Ok(updatedRecipe));
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Przepis przepis = db.Przepisy.First(c => c.PrzepisID == id);

            if (przepis == null)
            {
                return(HttpNotFound());
            }

            return(View(przepis));
        }
示例#18
0
        public ActionResult Create(Przepis przepis)
        {
            string login = User.Identity.GetUserName();

            if (login == "")
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    przepis.Ktododal = login;
                    db.Przepisy.Add(przepis);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                return(View(przepis));
            }
        }
示例#19
0
        public void AddPrzepis(Przepis przepis)
        {
            var first  = GetPrzepisy().ToList();
            var sec    = System.Text.Json.JsonSerializer.Serialize <Przepis>(przepis);
            var second = System.Text.Json.JsonSerializer.Deserialize <Przepis>(sec);

            first.Add(second);
            var przepisy = GetPrzepisyFromList(first);

            using (var outputStream = File.OpenWrite(JsonFileName))
            {
                System.Text.Json.JsonSerializer.Serialize <IEnumerable <Przepis> >(
                    new Utf8JsonWriter(outputStream, new JsonWriterOptions
                {
                    SkipValidation = true,
                    Indented       = true
                }),
                    przepisy
                    );
            }
        }
示例#20
0
 /// <summary>
 /// Daje możliwość zatwierdzić przepis
 /// </summary>
 /// <param name="id_admin">musi być administrator</param>
 /// <param name="id_przepis">niezatwierdzony przepis</param>
 /// <param name="zatwierdz">czy zatwierdzić</param>
 /// <returns>czy udało się</returns>
 public bool AdminZatwierdzPrzepis(int id_admin, int id_przepis, bool zatwierdz)
 {
     try
     {
         Uzytkownik super = bazaContext.setUzytkownicy.Where(u => u.Id == id_admin).SingleOrDefault();
         if (super.SuperUser == true)
         {
             Przepis przepis = bazaContext.setPrzepisy.Where(p => p.Id == id_przepis).SingleOrDefault();
             przepis.Zatwierdzony = zatwierdz;
             bazaContext.SaveChanges();
             return(true);
         }
         else
         {
             throw new FaultException("Uzytkownik niema takich uprawnien!");
         }
     }
     catch (FaultException e)
     {
         throw new FaultException("Nie da rady!");
     }
 }//done
 public async Task<IActionResult> Create([Bind("Id,Nazwa,Hasztag,Ocena,Image,Tresc,KategoriaId")] Przepis przepis, List<IFormFile> Image)
 {
     if (ModelState.IsValid)
     {
         foreach (var item in Image)
         {
             if (item.Length > 0)
             {
                 using (var stream = new MemoryStream())
                 {
                     await item.CopyToAsync(stream);
                     przepis.Image = stream.ToArray();
                 }
             }
         }
         
         _context.Add(przepis);
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(Index));
     }
     ViewData["KategoriaId"] = new SelectList(_context.Kategorie, "Id", "Nazwa", przepis.KategoriaId);
     return View(przepis);
 }
示例#22
0
        public IActionResult OnPost()
        {
            var allGood = true;

            var ID           = Guid.NewGuid().ToString().Substring(0, 5);
            var Category     = Request.Form["Category"];
            var PrzepisTitle = Request.Form["PrzepisTitle"];
            var Description  = Request.Form["Description"];
            var Ingredients  = Request.Form["Ingredients"];
            var HowTo        = Request.Form["HowTo"];


            if (PrzepisTitle.Equals(""))
            {
                allGood            = false;
                ViewData["Error1"] = "Pole Tytuł nie może pozostać puste!";
            }
            if (Description.Equals(""))
            {
                allGood            = false;
                ViewData["Error2"] = "Pole Opis nie może pozostać puste!";
            }
            if (Ingredients.Equals(""))
            {
                allGood            = false;
                ViewData["Error3"] = "Pole Składniki nie może pozostać puste!";
            }
            if (HowTo.Equals(""))
            {
                allGood            = false;
                ViewData["Error4"] = "Pole Sposób przygotowania nie może pozostać puste!";
            }

            if (this.Image != null && allGood == true)
            {
                var fileName = GetUniqueName(this.Image.FileName);
                ViewData["Imagename"] = fileName;
                var filePath = Path.Combine(WebHostEnvironment.WebRootPath, "data", "images", fileName);
                var fs       = new FileStream(filePath, FileMode.Create);
                this.Image.CopyTo(fs);
                fs.Close();
            }
            else
            {
                allGood           = false;
                ViewData["Error"] = "Musisz dodać zdjęcie!";
            }

            if (allGood)
            {
                string[] Ingr = Ingredients.First().Split("; ", StringSplitOptions.RemoveEmptyEntries);
                if (Ingr[0].Contains(';'))
                {
                    Ingr = Ingredients.First().Split(';', StringSplitOptions.RemoveEmptyEntries);
                }

                Przepis przepis = new Przepis();
                przepis.ID          = ID;
                przepis.Category    = Category;
                przepis.Title       = PrzepisTitle;
                przepis.Image       = (string)ViewData["Imagename"];
                przepis.Description = Description;
                przepis.Ingredients = Ingr;
                przepis.HowTo       = HowTo;

                JsonFilePrzepisService service = new JsonFilePrzepisService(WebHostEnvironment);
                service.AddPrzepis(przepis);

                ViewData["Thanks"] = "Przepis został dodany, dziękujemy!";
            }
            else
            {
                ViewData["ID"]           = ID;
                ViewData["Category"]     = Category;
                ViewData["PrzepisTitle"] = PrzepisTitle;
                ViewData["Description"]  = Description;
                ViewData["Ingredients"]  = Ingredients;
                ViewData["HowTo"]        = HowTo;
            }

            return(Page());
        }
示例#23
0
        // POST api/values
        public String Post([FromBody] Recipe recipe)
        {
            KsiazkaKucharskaModelContainer db = new KsiazkaKucharskaModelContainer();

            // Security check
            var element = from usr in db.UzytkownikSet
                          where usr.token == recipe.token
                          select usr;

            if (element.Count() == 0)
            {
                return("Incorrect token!");
            }

            Przepis przepis = new Przepis();

            przepis.nazwa           = recipe.name;
            przepis.opis            = recipe.description;
            przepis.kategoria       = recipe.category;
            przepis.przygotowanie   = recipe.preparation;
            przepis.skladniki       = recipe.ingredients;
            przepis.trudnosc        = recipe.difficulty;
            przepis.zdjecie         = recipe.photo;
            przepis.czas_wykonania  = recipe.readyIn;
            przepis.data_utworzenia = DateTime.Now;
            przepis.film            = recipe.video;

            if (przepis.nazwa.Length == 0)
            {
                return("Incorrect name!");
            }
            if (przepis.opis.Length == 0)
            {
                return("Incorrect description!");
            }
            if (przepis.kategoria.Length == 0)
            {
                return("Incorrect category!");
            }
            if (przepis.przygotowanie.Length == 0)
            {
                return("Incorrect preparation!");
            }
            if (przepis.skladniki.Length == 0)
            {
                return("Incorrect ingredients!");
            }
            if (przepis.trudnosc == null)
            {
                return("Incorrect difficulty!");
            }
            if (przepis.czas_wykonania <= 0)
            {
                return("Incorrect readyIn time!");
            }

            db.PrzepisSet.Add(przepis);

            db.SaveChanges();

            return("Recipe was added!");
        }