Пример #1
0
        public Object Put(ContactResource contactResource)
        {
            LogRequest();

            if (contactResource == null) { return "Contact is required"; }
            if (contactResource.ContactId == null) { return "Contact.ContactId is required"; }

            int contactId = contactResource.ContactId.Value;
            var list = _db.Contacts.Where(x => x.ContactId == contactId).ToList();
            Contact contact = null;

            if (list.Any())
            {
                contact = list.First();
                contact.Name = SafeTrim(contactResource.Name);
                contact.Address = SafeTrim(contactResource.Address);
                contact.PhoneNo = SafeTrim(contactResource.PhoneNo);
                contact.EmployeeId = contactResource.EmployeeId;
                _db.SaveChanges();
            }

            return contact;
        }
Пример #2
0
        public Object Post(ContactResource contactResource)
        {
            LogRequest();

            if (contactResource == null) { return "Contact is required"; }
            if (contactResource.Name == null) { return "Contact.Name is required"; }
            if (contactResource.Address == null) { return "Contact.Address is required"; }
            if (contactResource.PhoneNo == null) { return "Contact.PhoneNo is required"; }
            if (contactResource.MobileNo == null) { return "Contact.MobileNo is required"; }
            if (contactResource.EmployeeId <= 0) { return "Contact.EmployeeId is required"; }

            var contact = new Contact
            {
                Name = SafeTrim(contactResource.Name),
                Address = SafeTrim(contactResource.Address),
                PhoneNo = SafeTrim(contactResource.PhoneNo),
                MobileNo = SafeTrim(contactResource.MobileNo),
                EmployeeId = contactResource.EmployeeId
            };
            _db.Contacts.Add(contact);
            _db.SaveChanges();

            return contact;
        }