Пример #1
0
        public HttpResponseMessage put(string id, LOGINDETAILS logindetails)
        {
            try
            {
                using (LoginDetailsEntities entities = new LoginDetailsEntities())
                {
                    var entity = entities.LOGINDETAILS.FirstOrDefault(e => e.EmployeeId == id);
                    if (entity == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "LoginDetails doesnt exist"));
                    }
                    else
                    {
                        entity.EmployeeId = logindetails.EmployeeId;
                        entity.Password   = logindetails.Password;
                        entities.SaveChanges();

                        return(Request.CreateResponse(HttpStatusCode.OK));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
Пример #2
0
 public HttpResponseMessage post([FromBody] LOGINDETAILS logindetails)
 {
     try
     {
         using (LoginDetailsEntities entities = new LoginDetailsEntities())
         {
             entities.LOGINDETAILS.Add(logindetails);
             entities.SaveChanges();
             HttpResponseMessage message = Request.CreateResponse(HttpStatusCode.Created, logindetails);
             message.Headers.Location = new Uri(Request.RequestUri + logindetails.EmployeeId.ToString());
             return(message);
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }