예제 #1
0
        public IHttpActionResult PutContact(int id, Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public User Create(User user)
        {
            if (user == null)
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(user.Firm) || string.IsNullOrWhiteSpace(user.Name) || string.IsNullOrWhiteSpace(user.SurName))
            {
                return(null);
            }

            user.CreatedDate = DateTime.Now;
            user.UserId      = Guid.NewGuid();
            user.IsActive    = true;

            try
            {
                database.Users.Add(user);
                database.SaveChanges();
            }
            catch (Exception)
            {
                return(null);
            }


            return(user);
        }
예제 #3
0
        public Contact Create(Contact model)
        {
            if (model == null)
            {
                return(null);
            }

            if (string.IsNullOrWhiteSpace(model.Phone) || string.IsNullOrWhiteSpace(model.Email) || string.IsNullOrWhiteSpace(model.Location))
            {
                return(null);
            }

            model.Location = model.Location.Trim().ToUpper().First() + model.Location.Trim().ToLower().Substring(1);

            try
            {
                database.Contacts.Add(model);
                database.SaveChanges();

                return(model);
            }
            catch (Exception e)
            {
                return(null);
            }
        }