Exemplo n.º 1
0
        public IHttpActionResult PutPhotoAlbum(int id, PhotoAlbum photoAlbum)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != photoAlbum.PhotoAlbumId)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public IActionResult InventoryDelete(int userId, int inventoryId)
        {
            var result = _context.UserAndInventoriyRelationship.FirstOrDefault(x => x.UserId == userId && x.InventoriyId == inventoryId);

            _context.UserAndInventoriyRelationship.Remove(result);
            _context.SaveChanges();
            return(RedirectToAction(nameof(Inventory), new { id = userId }));
        }
Exemplo n.º 3
0
        public IHttpActionResult PostPost(Post post)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Posts.Add(post);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = post.PostId }, post));
        }
        public IActionResult SaveInventory(InventoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                Inventory inventory = new Inventory()
                {
                    Name   = model.Name,
                    Status = model.Status,
                    Cost   = model.Cost
                };

                _context.Inventories.Add(inventory);
            }
            _context.SaveChanges();
            return(RedirectToAction(nameof(SaveInventory)));
        }
Exemplo n.º 5
0
        public bool Get()
        {
            string ip = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            Access a  = new Access(Guid.NewGuid().ToString("N"), ip, DateTime.Now);

            _accessContext.Access.Add(a);
            return(_accessContext.SaveChanges() > 0);
        }
        public IActionResult SaveUser(UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = new User()
                {
                    FirstName  = model.FirstName,
                    LastName   = model.LastName,
                    Department = model.Department,
                    Mission    = model.Mission
                };

                _context.Users.Add(user);
                _context.SaveChanges();
            }

            return(RedirectToAction(nameof(SaveUser)));
        }
Exemplo n.º 7
0
 public void Create(Post post)
 {
     db.Posts.Add(post);
     db.SaveChanges();
 }
 public void Create(Profile profile)
 {
     db.Profiles.Add(profile);
     db.SaveChanges();
 }