public ActionResult <string> Update([Required] int id, [FromBody][Required] ContactJson contact)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     return(repository.UpdateContact(id, contact).Result);
 }
        public ResponseObjects.ApiResponse<ResponseObjects.ContactJson> Add(ContactJson contact)
        {
            Dictionary<string, string> UrlParameters = new Dictionary<string, string>();
            Dictionary<string, dynamic> Parameters = new Dictionary<string, dynamic>();

            UrlParameters.Add("msisdn", contact.Msisdn);

            ResponseObjects.ApiResponse<ResponseObjects.ContactJson> serverResponse = this.RequestToApi<ResponseObjects.ContactJson>("contacts/" + contact.Msisdn, request.post, UrlParameters, null, false, (Object)contact);
            return serverResponse;
        }
        public ResponseObjects.ApiResponse <ResponseObjects.ContactJson> Add(ContactJson contact)
        {
            Dictionary <string, string>  UrlParameters = new Dictionary <string, string>();
            Dictionary <string, dynamic> Parameters    = new Dictionary <string, dynamic>();

            UrlParameters.Add("msisdn", contact.Msisdn);

            ResponseObjects.ApiResponse <ResponseObjects.ContactJson> serverResponse = this.RequestToApi <ResponseObjects.ContactJson>("contacts/" + contact.Msisdn, request.post, UrlParameters, null, false, (Object)contact);
            return(serverResponse);
        }
Example #4
0
        /// <inheritdoc />
        public async Task <dynamic> UpdateContact(long id, ContactJson Contact)
        {
            //Get contact object
            Contact contact = _context.Contact.Where(c => c.Id == id).FirstOrDefault();

            //Update if exist
            if (contact != null)
            {
                //Update from contact table first
                contact.Email = Contact.email;
                contact       = _context.Contact.Update(contact).Entity;

                //Update name table
                Name name = _context.Name.First(n => n.IName == contact.IName);
                name.First  = Contact.name.First;
                name.Last   = Contact.name.Last;
                name.Middle = Contact.name.Middle;
                _context.Name.Update(name);

                //Update address table
                Address address = _context.Address.First(a => a.IAddress == contact.IAddress);
                address.Street = Contact.address.Street;
                address.City   = Contact.address.City;
                address.State  = Contact.address.State;
                address.Zip    = Contact.address.Zip;
                _context.Address.Update(address);

                //Get the right Phone List object based on contact id (foreign key)
                List <Phone> phonelist = _context.Phone.Where(p => p.ContactId == contact.Id).ToList();
                //Delete existing phones since primary key (iPhone) is not being passed
                foreach (Phone phone in phonelist)
                {
                    _context.Phone.Remove(phone);
                }
                //Add Phone list from input
                foreach (Phone phone in Contact.phone)
                {
                    phone.ContactId = contact.Id;
                    _context.Phone.Add(phone);
                }

                await _context.SaveChangesAsync();    //commit changes

                return("Contact Updated");
            }
            else
            {
                return("Contact not found");
            }
        }
        /// <summary>
        /// Adds a new contact
        /// </summary>
        /// <param name="Msisdn">country code + phone number</param>
        /// <param name="FirstName">contacts first name</param>
        /// <param name="LastName">contacts last name</param>        
        /// <returns></returns>
        public ResponseObjects.ApiResponse<ResponseObjects.ContactJson> Add(string countryCode, string Msisdn, string FirstName = null, string LastName = null)
        {
            Dictionary<string, string> UrlParameters = new Dictionary<string, string>();
               Dictionary<string, dynamic> Parameters = new Dictionary<string, dynamic>();

               UrlParameters.Add("msisdn", Msisdn);

               ContactJson contact = new ContactJson();
               contact.Msisdn = Msisdn;
               contact.FirstName = FirstName;
               contact.LastName = LastName;
               contact.CountryCode = countryCode;

               return Add(contact);
        }
        /// <summary>
        /// Adds a new contact
        /// </summary>
        /// <param name="Msisdn">country code + phone number</param>
        /// <param name="FirstName">contacts first name</param>
        /// <param name="LastName">contacts last name</param>
        /// <returns></returns>
        public ResponseObjects.ApiResponse <ResponseObjects.ContactJson> Add(string countryCode, string Msisdn, string FirstName = null, string LastName = null)
        {
            Dictionary <string, string>  UrlParameters = new Dictionary <string, string>();
            Dictionary <string, dynamic> Parameters    = new Dictionary <string, dynamic>();

            UrlParameters.Add("msisdn", Msisdn);

            ContactJson contact = new ContactJson();

            contact.Msisdn      = Msisdn;
            contact.FirstName   = FirstName;
            contact.LastName    = LastName;
            contact.CountryCode = countryCode;

            return(Add(contact));
        }
Example #7
0
        /// <inheritdoc />
        public List <ContactJson> GetContact(long id)
        {
            List <ContactJson>   cl   = new List <ContactJson>();
            IQueryable <Contact> temp = (id == 0) ? _context.Contact : _context.Contact.Where(c => c.Id == id);

            foreach (Contact c in temp)
            {
                ContactJson cc = new ContactJson(c.Id,
                                                 _context.Name.First(n => n.IName == c.IName),
                                                 _context.Address.First(a => a.IAddress == c.IAddress),
                                                 _context.Phone.Where(p => p.ContactId == c.Id).ToList(),
                                                 c.Email);
                cl.Add(cc);
            }

            return(cl);
        }
        public ActionResult <HttpResponseMessage> Add([FromBody][Required] ContactJson contact)
        {
            HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.Created);

            if (!ModelState.IsValid)
            {
                message.StatusCode   = HttpStatusCode.InternalServerError;
                message.ReasonPhrase = "Invalid JSON parameter";
            }
            if (repository.AddContact(contact).Result.Id == 0)
            {
                message.StatusCode   = HttpStatusCode.InternalServerError;
                message.ReasonPhrase = "Contact already exist";
            }

            return(message);
        }
        public JsonResult GetAllContacts()
        {
            List <ContactJson> contactsJson = new List <ContactJson>();
            List <Contact>     contacts     = _ContactService.GetAll();

            foreach (Contact contact in contacts)
            {
                ContactJson contactJson = new ContactJson
                {
                    id          = contact.IdContact.ToString(),
                    name        = contact.Name,
                    role        = contact.Role,
                    phoneNumber = contact.PhoneNumber,
                    comChannel  = contact.ComChannel,
                };
                contactsJson.Add(contactJson);
            }

            return(Json(contactsJson));
        }
Example #10
0
        /// <inheritdoc />
        public async Task <ContactJson> AddContact(ContactJson Contact)
        {
            if (!_context.Name.Any(n => n.First == Contact.name.First && n.Last == Contact.name.Last))
            {
                Contact.name    = _context.Name.Add(Contact.name).Entity;
                Contact.address = _context.Address.Add(Contact.address).Entity;
                await _context.SaveChangesAsync();

                Contact contact = new Contact(Contact.name.IName, Contact.address.IAddress, Contact.email);
                contact = _context.Contact.Add(contact).Entity;
                await _context.SaveChangesAsync();

                foreach (Phone phone in Contact.phone)
                {
                    phone.ContactId = contact.Id;
                    _context.Phone.Add(phone);
                }

                Contact.Id = contact.Id;
                await _context.SaveChangesAsync();
            }
            return(Contact);
        }
 private void AddToJsonList(ContactView c, string mode)
 {
     var found = contactJsons.Where(x => x.Id == c.Id).FirstOrDefault();
     bool isFound = found != null ? true : false;
     if (!isFound)
     {
         ContactJson cj = new ContactJson();
         cj = cj.Clone(c, mode);
         contactJsons.Add(cj);
     }
     else
     {
         if (mode == MyUtils.DELETE)
         {
             ContactJson cj = new ContactJson();
             cj = cj.Clone(c, mode);
             cj.ContactAction = MyUtils.DELETE;
             contactJsons.Remove(found);
             contactJsons.Add(cj);
         }
         if (mode == MyUtils.UPDATE)
         {
             ContactJson cj = new ContactJson();
             cj = cj.Clone(c, mode);
             if (c.Id > oldPrinterMaxID)
             {
                 contactJsons.Remove(found);
                 cj.ContactAction = MyUtils.ADD;
             }
             else
             {
                 contactJsons.Remove(found);
                 cj.ContactAction = MyUtils.UPDATE;
             }
             contactJsons.Add(cj);
         }
     }
 }