コード例 #1
0
        public IActionResult Put(string id, [FromBody] WebAPI.Employees.Models.Public.Employee employee)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(BadRequest());
            }
            if (employee != null)
            {
                return(BadRequest());
            }
            if (id != employee.Id)
            {
                return(BadRequest());
            }

            if (!serializer.EmployeeExists(id))
            {
                return(NotFound());
            }

            var internalEmployee = Helpers.EmployeeHelper.ConvertToInternalObject(employee);
            //merge the persist lists
            var existingObject = serializer.GetEmployee(id);

            Helpers.EmployeeHelper.MergeExisting(existingObject, internalEmployee);

            serializer.UpdateEmployee(id, internalEmployee);
            return(NoContent());
        }
コード例 #2
0
        public static WebAPI.Employees.Models.Public.Employee ConvertToPublicObject(WebAPI.Employees.Models.Domain.InternalEmployee model)
        {
            var employee = new WebAPI.Employees.Models.Public.Employee()
            {
                EmailAddress = model.EmailAddress,
                FirstName    = model.EmployeeName.FirstName,
                MiddleName   = model.EmployeeName.MiddleName,
                LastName     = model.EmployeeName.LastName,
                Title        = model.EmployeeName.Title,
                Id           = model.PublicId
            };

            var job = model.JobDetails.OrderByDescending(m => m.StartDate).Take(1).FirstOrDefault();

            employee.Department     = job.Department;
            employee.JobDescription = job.Description;
            employee.JobTitle       = job.JobTitle;
            employee.Office         = job.Office;
            employee.StartDate      = job.StartDate;
            employee.Office         = job.Office;
            employee.SMSPhone       = GetPhone(Models.Domain.PhoneNumberTypes.SMS, model);
            employee.WorkPhone      = GetPhone(Models.Domain.PhoneNumberTypes.Work, model);
            employee.HomePhone      = GetPhone(Models.Domain.PhoneNumberTypes.Home, model);
            employee.HomeAddress    = GetAddress(Models.Domain.AddressTypes.Home, model);
            employee.WorkAddress    = GetAddress(Models.Domain.AddressTypes.Work, model);

            return(employee);
        }
コード例 #3
0
        public IActionResult Post([FromBody] WebAPI.Employees.Models.Public.Employee model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (serializer.EmployeeExists(model.Id))
            {
                return(BadRequest("Employee exists"));
            }

            var employee         = serializer.AddEmployee(Helpers.EmployeeHelper.ConvertToInternalObject(model));
            var externalEmployee = Helpers.LinkBuilder.AddHateoas(Url, Helpers.EmployeeHelper.ConvertToPublicObject(employee));

            return(Created("api/Employee", externalEmployee));
        }
コード例 #4
0
        public static WebAPI.Employees.Models.Domain.InternalEmployee ConvertToInternalObject(WebAPI.Employees.Models.Public.Employee model)
        {
            var employee = new WebAPI.Employees.Models.Domain.InternalEmployee()
            {
                EmailAddress = model.EmailAddress,
                PublicId     = model.Id,
                EmployeeName = new Models.Domain.Name()
                {
                    FirstName  = model.FirstName,
                    MiddleName = model.MiddleName,
                    LastName   = model.LastName,
                    Title      = model.Title
                },
                JobDetails = new System.Collections.Generic.List <Models.Domain.JobDetail>()
                {
                    new Models.Domain.JobDetail()
                    {
                        Department   = model.Department,
                        Description  = model.JobDescription,
                        JobTitle     = model.JobTitle,
                        Office       = model.Office,
                        StartDate    = model.StartDate,
                        SupervisorId = model.SupervisorId
                    }
                },
                PhoneNumbers = new System.Collections.Generic.List <Models.Domain.PhoneNumber>(),
                Addresses    = new System.Collections.Generic.List <Models.Domain.Address>()
            };

            if (!String.IsNullOrEmpty(model.WorkPhone))
            {
                employee.PhoneNumbers.Add(new Models.Domain.PhoneNumber()
                {
                    PhoneNumberType = Models.Domain.PhoneNumberTypes.Work, Number = model.WorkPhone
                });
            }
            if (!String.IsNullOrEmpty(model.HomePhone))
            {
                employee.PhoneNumbers.Add(new Models.Domain.PhoneNumber()
                {
                    PhoneNumberType = Models.Domain.PhoneNumberTypes.Home, Number = model.HomePhone
                });
            }
            if (!String.IsNullOrEmpty(model.SMSPhone))
            {
                employee.PhoneNumbers.Add(new Models.Domain.PhoneNumber()
                {
                    PhoneNumberType = Models.Domain.PhoneNumberTypes.SMS, Number = model.SMSPhone
                });
            }

            if (model.WorkAddress != null)
            {
                employee.Addresses.Add(new Models.Domain.Address()
                {
                    AddressType   = Models.Domain.AddressTypes.Work,
                    AddressLine1  = model.WorkAddress.AddressLine1,
                    AddressLine2  = model.WorkAddress.AddressLine2,
                    AddressLine3  = model.WorkAddress.AddressLine3,
                    City          = model.WorkAddress.City,
                    CountryCode   = model.WorkAddress.CountryCode,
                    PostalCode    = model.WorkAddress.PostalCode,
                    StateProvince = model.WorkAddress.StateProvince
                });
            }

            if (model.HomeAddress != null)
            {
                employee.Addresses.Add(new Models.Domain.Address()
                {
                    AddressType   = Models.Domain.AddressTypes.Work,
                    AddressLine1  = model.HomeAddress.AddressLine1,
                    AddressLine2  = model.HomeAddress.AddressLine2,
                    AddressLine3  = model.HomeAddress.AddressLine3,
                    City          = model.HomeAddress.City,
                    CountryCode   = model.HomeAddress.CountryCode,
                    PostalCode    = model.HomeAddress.PostalCode,
                    StateProvince = model.HomeAddress.StateProvince
                });
            }

            return(employee);
        }