Beispiel #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Feedlot feedlot = db.Feedlot.Find(id);

            db.Feedlot.Remove(feedlot);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "feedlotID,fName")] Feedlot feedlot)
 {
     if (ModelState.IsValid)
     {
         db.Entry(feedlot).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(feedlot));
 }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "feedlotID,fName")] Feedlot feedlot)
        {
            if (ModelState.IsValid)
            {
                db.Feedlot.Add(feedlot);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(feedlot));
        }
Beispiel #4
0
        // GET: Feedlots/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Feedlot feedlot = db.Feedlot.Find(id);

            if (feedlot == null)
            {
                return(HttpNotFound());
            }
            return(View(feedlot));
        }
    public async Task <Feedlot> Create(Feedlot feedlot)
    {
        var newFeedlot = new Feedlot
        {
            Name    = feedlot.Name,
            Owner   = feedlot.Owner,
            Summary = feedlot.Summary
        };

        _context.Feedlots.Add(newFeedlot);
        await _context.SaveChangesAsync();

        return(newFeedlot);
    }
        public async Task <ActionResult <Feedlot> > Post(Feedlot feedlot)
        {
            var existingFeedlot = _feedlotService.FindExisting(feedlot.Name);

            if (existingFeedlot)
            {
                return(Conflict("This feedlot already exists"));
            }

            var newFeedlot = await _feedlotService.Create(feedlot);

            var resourceUrl = Path.Combine(Request.Path.ToString(), Uri.EscapeUriString(newFeedlot.Name));

            return(Created(resourceUrl, newFeedlot));
        }
Beispiel #7
0
        public async Task <ActionResult <User> > Register(User user)
        {
            var feedlots = _context.Feedlots.ToList();

            if (feedlots.Count < 1)
            {
                var newFeedlot = new Feedlot {
                    Owner = "Brian", Summary = "Cool", Name = "Brians lot"
                };
                _context.Feedlots.Add(newFeedlot);
                await _context.SaveChangesAsync();
            }

            if (await _context.Users.Where(c => c.Email == user.Email).AnyAsync())
            {
                return(BadRequest(new { Email = "Email Already Exists" }));
            }

            if (await _context.Users.Where(c => c.UserName == user.Username).AnyAsync())
            {
                return(BadRequest(new { Username = "******" }));
            }

            var newUser = new AppUser
            {
                UserName = user.Username,
                Email    = user.Email,
            };

            var result = await _userManager.CreateAsync(newUser, user.Password);

            if (result.Succeeded)
            {
                return(new User
                {
                    DisplayName = user.Username,
                    Token = _jwtGenerator.GenerateToken(newUser),
                    Username = user.Username,
                });
            }

            return(StatusCode(StatusCodes.Status500InternalServerError, new { Error = "Problem creating user." }));
        }