Exemplo n.º 1
0
        public Contact Parse(ContactModel person)
        {
            var doan = uow.Doans.GetByName(person.DoanName, GetEnumFromDescription(person.MienName, typeof(MienList)));

            var contact = new Contact();

            contact.Role = (RoleList) person.Role;
            contact.DoanId = doan.Id;
            contact.SaintName = person.SaintName;
            contact.LastName = person.LastName;
            contact.MiddleName = person.MiddleName;
            contact.FirstName = person.FirstName;
            contact.Email = person.Email;
            contact.Gender = person.Gender;
            contact.DateOfBirth = person.DateOfBirth;
            contact.AddressLine = person.Address;
            contact.City = person.City;
            contact.State = person.State;
            contact.Zip = person.Zip;
            contact.Phone1 = person.Phone;
            contact.Status = person.Status;
            contact.Doan = doan;
            contact.SaMacDanhSaches = new List<SaMacDanhSach>();
            contact.LastUpdate = DateTime.Now;

            contact.SaMacDanhSaches.Add(uow.SaMacDanhSachs.GetById(4));
            return contact;
        }
Exemplo n.º 2
0
        // GET member by Id
        public HttpResponseMessage Get(int id)
        {
            try
            {
                var person = uow.Contacts.GetById(id);
                if (person != null)
                {

                    var member = new ContactModel()
                    {
                        Id = person.Id,
                        Role = (int)person.Role,
                        SaintName = person.SaintName,
                        LastName = person.LastName,
                        MiddleName = person.MiddleName,
                        FirstName = person.FirstName,
                        Email = person.Email,
                        Gender = person.Gender,
                        DateOfBirth = person.DateOfBirth,
                        Address = person.AddressLine,
                        City = person.City,
                        State = person.State,
                        Zip = person.Zip,
                        Phone = person.Phone1,
                        Status = person.Status,
                        MienId= uow.Doans.GetById(person.DoanId).MienId,
                        DoanId = person.DoanId,
                        DoanName = uow.Doans.GetById(person.DoanId).Name
                    };

                    return Request.CreateResponse(HttpStatusCode.OK, member);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }

            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error loading member information");
            }
        }
Exemplo n.º 3
0
        // PUT api/values/5
        public HttpResponseMessage Put(ContactModel member)
        {
            try
            {
                var updateContact = uow.Contacts.GetById(member.Id);
                // var role = (RoleList) GetEnumFromDescription(member.Role, typeof (RoleList));
                updateContact.Role = (RoleList)member.Role;
                //  db.DoanSet.First(d => d.Id == updateContact.DoanId).MienId = GetEnumFromDescription(member.MienName, typeof(MienList));
                updateContact.DoanId = member.DoanId;
                updateContact.SaintName = member.SaintName;
                updateContact.FirstName = member.FirstName;
                updateContact.MiddleName = member.MiddleName;
                updateContact.LastName = member.LastName;
                updateContact.Email = member.Email;
                updateContact.Gender = member.Gender;
                updateContact.DateOfBirth = member.DateOfBirth;
                updateContact.AddressLine = member.Address;
                updateContact.City = member.City;
                updateContact.State = member.State;
                updateContact.Zip = member.Zip;
                updateContact.Phone1 = member.Phone;
                updateContact.Status = member.Status;
                updateContact.LastUpdate = DateTime.Now;

                uow.Contacts.Update(updateContact);
                uow.Commit();
                member.MienName = GetEnumDescription((MienList)Enum.ToObject(typeof(MienList), uow.Doans.GetById(updateContact.DoanId).MienId));

                return Request.CreateResponse(HttpStatusCode.OK, member);

            }
            catch (Exception)
            {
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error updating the member");
            }
        }
Exemplo n.º 4
0
        // POST api/values
        public HttpResponseMessage Post(ContactModel person)
        {
            try
            {
                var doan = uow.Doans.GetByName(person.DoanName, person.MienId);
                var member = new Contact()
                {
                    //DoanId = 1,
                    Role = (RoleList)person.Role,
                    DoanId = doan.Id,
                    SaintName = person.SaintName,
                    LastName = person.LastName,
                    MiddleName = person.MiddleName,
                    FirstName = person.FirstName,
                    Email = person.Email,
                    Gender = person.Gender,
                    DateOfBirth = person.DateOfBirth,
                    AddressLine = person.Address,
                    City = person.City,
                    State = person.State,
                    Zip = person.Zip,
                    Phone1 = person.Phone,
                    Status = person.Status,
                    Doan = doan,
                    SaMacDanhSaches = new List<SaMacDanhSach>(),
                    LastUpdate = DateTime.Now,
                };

                member.SaMacDanhSaches.Add(uow.SaMacDanhSachs.GetById(4));

                uow.Contacts.Add(member);
                uow.Commit();
                var addedContact = uow.Contacts.GetById(member.Id);
                person.Id = addedContact.Id;
                return Request.CreateResponse(HttpStatusCode.Created, person);

            }
            catch (Exception ex)
            {
                if (ex.InnerException.InnerException.Message.Contains("Violation of UNIQUE KEY"))
                {
                    return Request.CreateResponse(HttpStatusCode.InternalServerError, "Member already exist or email address has been used");
                }
                else
                {
                    return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error adding a new member");
                }
                return Request.CreateResponse(HttpStatusCode.InternalServerError, "Error adding a new member");
            }
        }