Exemplo n.º 1
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            SmallCattle smallCattle = await db.SmallCattles.FindAsync(id);

            db.SmallCattles.Remove(smallCattle);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SmallCattle smallCattle = await db.SmallCattles.FindAsync(id);

            if (smallCattle == null)
            {
                return(HttpNotFound());
            }
            return(View(smallCattle));
        }
        public async Task <IActionResult> Create([Bind("Id,Code,BreedRU,BreedKK,BreedEN,DirectionRU,DirectionKK,DirectionEN,WeightRU,WeightKK,WeightEN,ShearingsRU,ShearingsKK,ShearingsEN,WashedWoolYieldRU,WashedWoolYieldKK,WashedWoolYieldEN,FertilityRU,FertilityKK,FertilityEN,WoolLengthRU,WoolLengthKK,WoolLengthEN,TotalGoals,BredRU,BredKK,BredEN,RangeRU,RangeKK,RangeEN,FormFile,DescriptionRU,DescriptionKK,DescriptionEN")] SmallCattle smallCattle)
        {
            if (ModelState.IsValid)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await smallCattle.FormFile.CopyToAsync(memoryStream);

                    smallCattle.Photo = memoryStream.ToArray();
                }

                _context.Add(smallCattle);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(smallCattle));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Create([Bind(Include = "Id,Code,Breed,Direction,Weight,Shearings,WashedWoolYield,Fertility,WoolLength,TotalGoals,Bred,Range,Description")] SmallCattle smallCattle, HttpPostedFileBase Photo)
        {
            if (ModelState.IsValid)
            {
                if (Photo != null)
                {
                    MemoryStream target = new MemoryStream();
                    Photo.InputStream.CopyTo(target);
                    smallCattle.Photo = target.ToArray();
                }
                db.SmallCattles.Add(smallCattle);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(smallCattle));
        }
Exemplo n.º 5
0
        public ActionResult GetBreedInfo(
            string Code)
        {
            int code = Convert.ToInt32(Code);

            if (code > 400)
            {
                SmallCattle smallcattle = _context.SmallCattle.FirstOrDefault(s => s.Code == code);
                smallcattle.Img = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(smallcattle.Photo));
                return(Json(new
                {
                    smallcattle
                }));
            }
            else if (code > 300)
            {
                Horse horse = _context.Horse.FirstOrDefault(h => h.Code == code);
                horse.Img = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(horse.Photo));
                return(Json(new
                {
                    horse
                }));
            }
            else if (code > 200)
            {
                Cattle cattle = _context.Cattle.FirstOrDefault(c => c.Code == code);
                cattle.Img = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(cattle.Photo));
                return(Json(new
                {
                    cattle
                }));
            }
            else
            {
                Camel camel = _context.Camel.FirstOrDefault(c => c.Code == code);
                camel.Img = String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(camel.Photo));
                return(Json(new
                {
                    camel
                }));
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Code,BreedRU,BreedKK,BreedEN,DirectionRU,DirectionKK,DirectionEN,WeightRU,WeightKK,WeightEN,ShearingsRU,ShearingsKK,ShearingsEN,WashedWoolYieldRU,WashedWoolYieldKK,WashedWoolYieldEN,FertilityRU,FertilityKK,FertilityEN,WoolLengthRU,WoolLengthKK,WoolLengthEN,TotalGoals,BredRU,BredKK,BredEN,RangeRU,RangeKK,RangeEN,FormFile,DescriptionRU,DescriptionKK,DescriptionEN")] SmallCattle smallCattle)
        {
            if (id != smallCattle.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (smallCattle.FormFile != null && smallCattle.FormFile.Length > 0)
                    {
                        smallCattle.Photo = null;
                        using (var memoryStream = new MemoryStream())
                        {
                            await smallCattle.FormFile.CopyToAsync(memoryStream);

                            smallCattle.Photo = memoryStream.ToArray();
                        }
                    }

                    _context.Update(smallCattle);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SmallCattleExists(smallCattle.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(smallCattle));
        }