コード例 #1
0
        //[BasicAuthorization]
        //public HttpResponseMessage Get(string gender = "all")
        //{
        //    string username = Thread.CurrentPrincipal.Identity.Name;
        //    using (AIDummyDBEntities entities = new AIDummyDBEntities())
        //    {
        //        switch (username.ToLower())
        //        {
        //            case "male":
        //                return Request.CreateResponse(HttpStatusCode.OK,
        //                entities.Employee.Where(e => e.gender.ToLower() == "male").ToList());
        //            case "female":
        //                return Request.CreateResponse(HttpStatusCode.OK,
        //                entities.Employee.Where(e => e.gender.ToLower() == "female").ToList());
        //            default:
        //                return Request.CreateResponse(HttpStatusCode.BadRequest);
        //        }
        //    }

        //}

        public IEnumerable <Employee> Get()
        {
            using (AIDummyDBEntities entities = new AIDummyDBEntities())
            {
                return(entities.Employee.ToList());
            }
        }
コード例 #2
0
ファイル: EmployeeSecurity.cs プロジェクト: nipa0827/WEB_API
 public static bool Login(string username, string password)
 {
     using (AIDummyDBEntities entitis = new AIDummyDBEntities()){
         return(entitis.Users.Any(user => user.username.Equals(username, StringComparison.OrdinalIgnoreCase) &&
                                  user.password.Equals(password, StringComparison.OrdinalIgnoreCase)));
     }
 }
コード例 #3
0
 public HttpResponseMessage Delete(int id)
 {
     try{
         using (AIDummyDBEntities entity = new AIDummyDBEntities()){
             entity.Employee.Remove(entity.Employee.FirstOrDefault(e => e.id == id));
             entity.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK, "Employee deleted successfully."));
         }
     } catch (Exception ex) {
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee id is not valid", ex));
     }
 }
コード例 #4
0
        public HttpResponseMessage Get(int id)
        {
            using (AIDummyDBEntities entities = new AIDummyDBEntities())
            {
                var entity = entities.Employee.FirstOrDefault(e => e.id == id);

                if (entity != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, entity));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee not found"));
                }
            }
        }
コード例 #5
0
        public HttpResponseMessage Put(int id, [FromBody] Employee employee)
        {
            using (AIDummyDBEntities entities = new AIDummyDBEntities()){
                var entity = entities.Employee.FirstOrDefault(e => e.id == id);

                if (entity != null)
                {
                    entity.name   = employee.name;
                    entity.age    = employee.age;
                    entity.gender = employee.gender;

                    entities.SaveChanges();

                    return(Request.CreateResponse(HttpStatusCode.OK, "OKKKK"));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Employee not found"));
                }
            }
        }
コード例 #6
0
        public HttpResponseMessage Post(Employee employee)
        {
            string path = @"C:\Users\Leads\Desktop\temp.txt";

            using (StreamWriter sw = File.AppendText(path))
            {
                sw.WriteLine(employee.name + "\t" + employee.age + "\t" + employee.gender);
            }

            try
            {
                using (AIDummyDBEntities entities = new AIDummyDBEntities())
                {
                    entities.Employee.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.BadRequest, ex));
            }
        }