public ActionResult Create([Bind(Include = "ContactID,PhoneTypeID,Number")] PhoneNumber phoneNumber)
        {
            if (ModelState.IsValid)
            {
                // if created phone number is only phone number of  contact then that number is set to default
                Contact contact = db.Contacts.Find(phoneNumber.ContactID);
                if (contact.PhoneNumbers.Count == 0)
                {
                    phoneNumber.Default = true;
                }
                else
                {
                    phoneNumber.Default = false;
                }

                db.PhoneNumbers.Add(phoneNumber);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ContactID   = new SelectList(db.Contacts, "ContactID", "FullName", phoneNumber.ContactID);
            ViewBag.PhoneTypeID = new SelectList(db.PhoneTypes, "PhoneTypeID", "Type", phoneNumber.PhoneTypeID);

            return(View(phoneNumber));
        }
Beispiel #2
0
        public IHttpActionResult PutPerson([FromUri] int id, [FromBody] Person person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public TEntity Add(TEntity entity)
        {
            dbContext.Set <TEntity>().Add(entity);
            dbContext.SaveChanges();

            return(entity);
        }
        public IActionResult Put(long entryId, [FromBody] Entry entry)
        {
            _context.Entries.Update(entry);
            _context.SaveChanges();

            return(Ok());
        }
Beispiel #5
0
        public IActionResult AddContact([FromForm] ContactPM model)
        {
            var user = _phoneBookContext.Users.Include(q => q.ContactTypes).FirstOrDefault(p => p.ID == model.UserID);

            if (user != null)
            {
                if (user.ContactTypes == null)
                {
                    ContactTypes contactTypes = new ContactTypes();
                    contactTypes.Email    = model.Email;
                    contactTypes.Phone    = model.Phone;
                    contactTypes.Location = model.Location;
                    contactTypes.UserID   = model.UserID;

                    _phoneBookContext.ContactTypes.Add(contactTypes);
                    _phoneBookContext.SaveChanges();

                    return(Ok($"ID'si {model.UserID} olan kişiye iletişim bilgisi eklendi!"));
                }
                else
                {
                    return(BadRequest($"ID'si {model.UserID} olan kişinin zaten iletişim bilgisi var!(güncelleme istenmemiş)"));
                }
            }
            else
            {
                return(BadRequest($"ID'si {model.UserID} olan kişi bulunamadı!"));
            }
        }
        public IHttpActionResult PostAddPerson(PhoneBook person)
        {
            if (ModelState.IsValid)
            {
                //var error1 = db.PhoneBooks.Where(p => p.Name.ToUpper() == person.Name.ToUpper());
                var error = db.PhoneBooks.SingleOrDefault(p => p.ID == person.ID);
                if (error == null)
                {
                    db.PhoneBooks.Add(person);
                    db.SaveChanges();

                    // create http response with created status code and listing serialised as content and Location header set to URI for new resource
                    string uri = Url.Link("DefaultApi", new { id = person.ID });
                    return(Created(uri, person));
                }
                else
                {
                    return(BadRequest("Number or Name already exists"));
                }
            }
            else
            {
                return(BadRequest(ModelState));              // 400
            }
        }
        public Person AddPerson(Person person)
        {
            person = _phoneBookContext.Add(person).Entity;

            _phoneBookContext.SaveChanges();

            return(person);
        }
 public ActionResult Create([Bind(Include = "ID,FirstName,LastName,PhoneNumber,Email,AddressOne,AddressTwo,PinCode,IsActive,CountryId,StateId,CityId")] People people)
 {
     if (ModelState.IsValid)
     {
         db.Peoples.Add(people);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(people));
 }
Beispiel #9
0
        public ActionResult Create([Bind(Include = "CuntryId,CountryName,IsActive")] Country country)
        {
            if (ModelState.IsValid)
            {
                db.Countries.Add(country);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(country));
        }
        public ActionResult Create([Bind(Include = "FirstName,LastName,Address,Email")] Contact contact)
        {
            if (ModelState.IsValid)
            {
                db.Contacts.Add(contact);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contact));
        }
        public ActionResult Create([Bind(Include = "StateId,StateName,IsActive,CountryId")] State state)
        {
            if (ModelState.IsValid)
            {
                db.States.Add(state);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CountryId = new SelectList(db.Countries, "CountryId", "CountryName", state.CountryId);
            return(View(state));
        }
Beispiel #12
0
        public ActionResult Create([Bind(Include = "CityId,CityName,IsActive,StateId")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.StateId = new SelectList(db.States, "StateId", "StateName", city.StateId);
            return(View(city));
        }
Beispiel #13
0
        public ActionResult <Person> Delete(int Id)
        {
            var person = _PhoneBookContext.Persons.SingleOrDefault(p => p.Id == Id);

            if (person == null)
            {
                return(NotFound());
            }

            _PhoneBookContext.Persons.Remove(person);
            _PhoneBookContext.SaveChanges();
            return(Ok());
        }
Beispiel #14
0
 public bool EditContact(ContactDTO model)
 {
     try
     {
         using (var dbContext = new PhoneBookContext())
         {
             var contact = new Contact();
             contact.Id   = model.Id;
             contact.Name = model.Name;
             foreach (var field in model.ContactFields)
             {
                 var cf = new ContactField();
                 cf.Id        = field.Id;
                 cf.Field     = field.Field;
                 cf.Value     = field.Value;
                 cf.ContactId = field.ContactId;
                 dbContext.ContactField.AddOrUpdate(cf);
             }
             dbContext.Contact.AddOrUpdate(contact);
             dbContext.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Beispiel #15
0
 public void Add(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var addedObject = context.Entry(person);
         addedObject.State = EntityState.Added;
         context.SaveChanges();
     }
 }
Beispiel #16
0
 public void Update(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var updatedObject = context.Entry(person);
         updatedObject.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Beispiel #17
0
 public void Delete(Person person)
 {
     using (PhoneBookContext context = new PhoneBookContext())
     {
         var deletedObject = context.Entry(person);
         deletedObject.State = EntityState.Deleted;
         context.SaveChanges();
     }
 }
Beispiel #18
0
 public ActionResult AddSave(Contact contact)
 {
     using (PhoneBookContext db = new PhoneBookContext())
     {
         db.Contacts.Add(contact);
         db.SaveChanges();
     }
     return(Redirect("/Dist/Index"));
 }
Beispiel #19
0
        public bool Add(Person person)
        {
            try
            {
                person.Created = DateTime.Now;

                person.Updated = DateTime.Now;

                _phoneBookContext.People.Add(person);

                _phoneBookContext.SaveChanges();

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public void Add(PhoneNumber item)
        {
            phoneNumber.Number    = item.Number;
            phoneNumber.ContactId = item.ContactId;

            using (var context = new PhoneBookContext())
            {
                context.PhoneNumbers.Add(phoneNumber);
                context.SaveChanges();
            }
        }
Beispiel #21
0
        public void Add(Contact item)
        {
            contact.Firstname = item.Firstname;
            contact.LastName  = item.LastName;
            contact.UserId    = item.UserId;

            using (var context = new PhoneBookContext())
            {
                context.Contacts.Add(contact);
                context.SaveChanges();
            }
        }
Beispiel #22
0
        public JsonResult DeleteChecked([FromBody] DeletedContacts contacts)
        {
            foreach (var id in contacts.Ids)
            {
                var contact = db.Contacts.Find(Convert.ToInt32(id));

                db.Contacts.Remove(contact);
            }

            db.SaveChanges();

            return(Json(true));
        }
Beispiel #23
0
        public IActionResult AddUser([FromForm] AddUserPM model)
        {
            if (ModelState.IsValid)
            {
                User user = new User();

                user.Name    = model.Name;
                user.SurName = model.SurName;
                user.Company = model.Company;

                _phoneBookContext.Add(user);
                _phoneBookContext.SaveChanges();

                model.ID = user.ID;

                return(Ok(model));
            }
            else
            {
                return(BadRequest(ModelState.Values));
            }
        }
Beispiel #24
0
        public void Add(User item)
        {
            user.UserName  = item.UserName;
            user.Password  = item.Password;
            user.FirstName = item.FirstName;
            user.LastName  = item.LastName;

            using (var context = new PhoneBookContext())
            {
                context.Users.Add(user);
                context.SaveChanges();
            }
        }
Beispiel #25
0
        public void GetsExistingPhoneBook()
        {
            var dummyPhoneBook = PhoneBookBuilder.Instance.DummyPhoneBook();

            _phoneBookContext.PhoneBooks.Add(dummyPhoneBook);
            _phoneBookContext.SaveChanges();
            int phoneBookId = dummyPhoneBook.Id;

            _output.WriteLine($"PhoneBookId: {phoneBookId}");

            var phoneBookFromRepo = _phoneBookRepository.GetById(phoneBookId);

            Assert.Equal(dummyPhoneBook.Id, phoneBookFromRepo.Id);
        }
Beispiel #26
0
        public ActionResult UpdateSave(Contact contact)
        {
            using (PhoneBookContext db = new PhoneBookContext())
            {
                db.Contacts.Attach(contact);
                db.Entry(contact)
                .Property(c => c.PhoneNumber).IsModified = true;
                db.Entry(contact)
                .Property(c => c.Name).IsModified = true;
                db.SaveChanges();
            }

            return(Redirect("/Dist/Index"));
        }
Beispiel #27
0
        public IActionResult CreatePerson([FromForm] PersonDTO person)
        {
            if (ModelState.IsValid)
            {
                Person newperson = new Person();
                newperson.Name    = person.Name;
                newperson.Surname = person.Surname;
                newperson.Company = person.Company;


                _phonecontext.people.Add(newperson);
                _phonecontext.SaveChanges();

                person.ID = newperson.ID;



                return(Ok(person));
            }
            else
            {
                return(BadRequest(ModelState.Values));
            }
        }
Beispiel #28
0
        public void Delete(Contact item)
        {
            contact = GetById(item.Id);

            if (contact == null)
            {
                throw new ArgumentNullException("Please choose contact to delete");
            }

            using (var context = new PhoneBookContext())
            {
                context.Contacts.Attach(contact);
                context.Contacts.Remove(contact);
                context.SaveChanges();
            }
        }
Beispiel #29
0
        public void Delete(User item)
        {
            user = GetById(item.Id);

            if (user == null)
            {
                throw new ArgumentNullException("Please choose user to delete");
            }

            using (var context = new PhoneBookContext())
            {
                context.Users.Attach(user);
                context.Users.Remove(user);
                context.SaveChanges();
            }
        }
Beispiel #30
0
        public IActionResult Delete(int id)
        {
            using (var context = new PhoneBookContext())
            {
                var person = context.Persons.FirstOrDefault(p => p.PersonId == id);

                if (person != null)
                {
                    context.Remove(person);
                    context.SaveChanges();

                    return(Ok());
                }
            }

            return(NotFound());
        }