Esempio n. 1
0
 public HttpResponseMessage Put(int id, [FromBody] EmployeeNew employee)
 {
     try
     {
         using (AdventureWorks2014Entities entities = new AdventureWorks2014Entities())
         {
             var entity = entities.EmployeeNews.FirstOrDefault(e => e.Id == id);
             if (entity == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee with Id = " + id.ToString() + "NotFound to update"));
             }
             else
             {
                 entity.Name        = employee.Name;
                 entity.Gender      = employee.Gender;
                 entity.City        = employee.City;
                 entity.DateOfBirth = employee.DateOfBirth;
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, entity));
             }
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
        public void Constructor_Assigns_Properties_From_Parameters(Guid newId, EmployeeNew employee)
        {
            var sut = new EmployeeCreateCommand(newId, employee);

            sut.NewId.Should().Be(newId);
            sut.Employee.Should().Be(employee);
        }
    public EmployeeCreateCommand(Guid newId, EmployeeNew employee)
    {
        Guard.Against.Default(newId, nameof(newId));
        Guard.Against.Null(employee, nameof(employee));

        NewId    = newId;
        Employee = employee;
    }
Esempio n. 4
0
        public void WriteEmployeeManagerManagerWithMonadsExample()
        {
            var m0 = new EmployeeNew {
                Name = "RB", Manager = Maybe <EmployeeNew> .None()
            };
            var m1 = new EmployeeNew {
                Name = "MJ", Manager = new Maybe <EmployeeNew>(m0)
            };
            var m2 = new EmployeeNew {
                Name = "MT", Manager = new Maybe <EmployeeNew>(m1)
            };

            var directorName = GetManagerManagerNameNew(m2);

            Assert.AreEqual("RB", directorName);
        }
Esempio n. 5
0
        // Below method return void and status code is 204i.e: no content
        //public void Post([FromBody] EmployeeNew employee)
        //{
        //    using (AdventureWorks2014Entities entities = new AdventureWorks2014Entities())
        //    {
        //        entities.EmployeeNews.Add(employee);
        //        entities.SaveChanges();
        //    }

        //}

        //below method return httpstatuscode 201 which is correct as per REST method for newly created item in api
        //This method also return
        public HttpResponseMessage Post([FromBody] EmployeeNew employee)
        {
            try {
                using (AdventureWorks2014Entities entities = new AdventureWorks2014Entities())
                {
                    entities.EmployeeNews.Add(employee);
                    entities.SaveChanges();
                    var message = Request.CreateResponse(HttpStatusCode.Created, employee);
                    message.Headers.Location = new Uri(Request.RequestUri + @"\" + employee.Id.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadGateway, ex));
            }
        }
Esempio n. 6
0
 public static EmployeeRecord From(Guid newId, EmployeeNew employee) =>
 new EmployeeRecord
 {
     Id                  = newId,
     PartitionKey        = newId.ToString(),
     Department          = employee.Department,
     EmploymentStartedOn = employee.EmploymentStartedOn,
     FirstName           = employee.FirstName,
     FirstNameLower      = employee.FirstName.ToLowerInvariant(),
     LastName            = employee.LastName,
     LastNameLower       = employee.LastName.ToLowerInvariant(),
     Email               = employee.Email,
     EmailLower          = employee.Email.ToLowerInvariant(),
     Phone               = employee.Phone,
     Status              = employee.Status,
     Title               = employee.Title
 };
Esempio n. 7
0
 static string GetManagerManagerNameNew(EmployeeNew employee)
 {
     return(employee.Manager
            .Bind(e => e.Manager)
            .Match(e => e.Name, () => null));
 }