Example #1
0
        public IHttpActionResult UpdateUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public ActionResult Index(int?CountValue)
        {
            var model = new Models.CountModel()
            {
                CountValue = CountValue.Value
            };

            using (var db = new FPContext())
            {
                var firstRecord = db.Counts.FirstOrDefault();
                if (firstRecord != null)
                {
                    firstRecord.CountValue = CountValue.Value;
                }
                else
                {
                    firstRecord = db.Counts.Add(new Count {
                        CountValue = CountValue.Value
                    });
                }

                db.SaveChanges();
            }

            return(View(model));
        }
        public void Post([FromBody] Dati dati)
        {
            FPContext db = new FPContext();

            db.Datis.Add(dati);
            db.SaveChanges();
        }
Example #4
0
 public bool Delete(User t)
 {
     using (var ctx = new FPContext())
     {
         ctx.Entry(ctx.Users.FirstOrDefault(x => x.Id == t.Id)).State = System.Data.Entity.EntityState.Deleted;
         ctx.SaveChanges();
         return(ctx.Users.FirstOrDefault(x => x.Id == t.Id) == null);
     }
 }
Example #5
0
 public User Create(User t)
 {
     using (var ctx = new FPContext())
     {
         ctx.Users.Add(t);
         ctx.SaveChanges();
         return(t);
     }
 }
Example #6
0
 public User Update(User t)
 {
     using (var ctx = new FPContext())
     {
         var userToUpdate = ctx.Users.FirstOrDefault(x => x.Id == t.Id);
         if (userToUpdate != null)
         {
             userToUpdate.FirstName = t.FirstName;
             userToUpdate.LastName  = t.LastName;
             userToUpdate.Email     = t.Email;
             userToUpdate.Company   = t.Company;
             userToUpdate.Type      = t.Type;
             userToUpdate.Password  = t.Password;
         }
         ctx.SaveChanges();
         return(t);
     }
 }