예제 #1
0
        public HttpResponseMessage Put(int id, [FromBody] Employee emp)
        {
            using (EmpDBEntities entities = new EmpDBEntities())
            {
                var entity = entities.Employees.FirstOrDefault(e => e.Id == id);
                if (entity == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Emp with Id: " + id.ToString() + " NOT FOUND!"));
                }
                try
                {
                    entity.Name       = emp.Name;
                    entity.Email      = emp.Email;
                    entity.PhotoPath  = emp.PhotoPath;
                    entity.Department = emp.Department;

                    entities.SaveChanges();
                    return(Request.CreateResponse(HttpStatusCode.OK, entity));
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                }
            }
        }
예제 #2
0
 public static bool Login(string username, string password)
 {
     using (EmpDBEntities entitys = new EmpDBEntities())
     {
         //this line below returnd either true or false
         return(entitys.Users.Any(user => user.UserName.Equals(username,
                                                               StringComparison.OrdinalIgnoreCase) && user.Password == password));
     }
 }
예제 #3
0
        public IEnumerable <Employee> Get()
        {
            string username = Thread.CurrentPrincipal.Identity.Name;

            using (EmpDBEntities entities = new EmpDBEntities())
            {
                return(entities.Employees.ToList());
            }
        }
예제 #4
0
        public JsonResult GetEmployees()
        {
            /*Taking record from EF and sending through Json*/

            EmpDBEntities context  = new EmpDBEntities();
            var           emp_data = context.Employees.Where(e => e.IsActive == 1).ToList();

            return(new JsonResult {
                Data = emp_data, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
예제 #5
0
        public static string refreshTToken()
        {
            string _token = "";

            string userName = "******";
            string passWord = "******";

            string BaseAddress = "http://localhost:56473/Token";

            using (var client = new HttpClient {
                BaseAddress = new Uri(BaseAddress)
            })
            {
                var token = client.PostAsync("Token",
                                             new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("grant_type", "password"),
                    new KeyValuePair <string, string>("username", userName),
                    new KeyValuePair <string, string>("password", passWord)
                })).Result.Content.ReadAsAsync <AuthenticationToken>().Result;

                Console.WriteLine("...");

                if (token != null)
                {
                    _token = token.access_token.ToString().Trim();
                    // insert accessToken to AccessToken table
                    // create new AccessToken record
                    Data_WebApi_Jquery.Models.AccessToken accessToken = new Data_WebApi_Jquery.Models.AccessToken();
                    accessToken.Created     = DateTime.Now;
                    accessToken.TokenString = token.access_token;



                    try
                    {
                        using (EmpDBEntities dc = new EmpDBEntities())
                        {
                            dc.AccessTokens.Add(accessToken);
                            dc.SaveChanges();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }

                    return(_token);
                }
            }
            return(_token);
        }
예제 #6
0
 //public Employee Get(int id)
 public HttpResponseMessage Get(int id)
 {
     using (EmpDBEntities entities = new EmpDBEntities())
     {
         var entity = entities.Employees.FirstOrDefault(s => s.Id == id);
         if (entity != null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, entity));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Emp with Id: " + id.ToString() + " NOT FOUND!"));
         }
     }
 }
예제 #7
0
        //public void Post([FromBody] Employee emp)
        public HttpResponseMessage Post([FromBody] Employee emp)
        {
            try
            {
                using (EmpDBEntities entities = new EmpDBEntities())
                {
                    entities.Employees.Add(emp);
                    entities.SaveChanges();

                    var message = Request.CreateResponse(HttpStatusCode.Created, emp);
                    message.Headers.Location = new Uri(Request.RequestUri + emp.Id.ToString());
                    return(message);
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
            }
        }
예제 #8
0
 public HttpResponseMessage Delete(int id)
 {
     try
     {
         using (EmpDBEntities entities = new EmpDBEntities())
         {
             var emp = entities.Employees.FirstOrDefault(e => e.Id == id);
             if (emp != null)
             {
                 entities.Employees.Remove(entities.Employees.FirstOrDefault(e => e.Id == id));
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, emp));
             }
             else
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Emp with Id: " + id.ToString() + " NOT FOUND!"));
             }
         }
     }catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
예제 #9
0
 public EmpleadoService()
 {
     ctx = new EmpDBEntities();
 }
예제 #10
0
 public Employees()
 {
     db = new EmpDBEntities();
     InitializeComponent();
     ListEmployees = new List <Employee>();
 }
예제 #11
0
 public Report()
 {
     db = new EmpDBEntities();
     InitializeComponent();
 }
예제 #12
0
        public ActionResult Index(Part7IndexView part7IndexView)
        {
            if (Session["SelectedProductName"] != null)
            {
                Test_String = Session["SelectedProductName"].ToString();
            }

            //await GetTokenDetails("*****@*****.**", "123456");

            string userName = part7IndexView.UserName.Trim();
            //string passWord = "******";
            string passWord    = part7IndexView.Password.Trim();
            string BaseAddress = "http://localhost:56473/Token";

            using (var client = new HttpClient {
                BaseAddress = new Uri(BaseAddress)
            })
            {
                var token = client.PostAsync("Token",
                                             new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair <string, string>("grant_type", "password"),
                    new KeyValuePair <string, string>("username", userName),
                    new KeyValuePair <string, string>("password", passWord)
                })).Result.Content.ReadAsAsync <AuthenticationToken>().Result;

                Console.WriteLine("...");

                if (token != null)
                {
                    part7IndexView.access_token = token.access_token.ToString().Trim();

                    client.DefaultRequestHeaders.Authorization =
                        new AuthenticationHeaderValue(token.token_type, token.access_token);

                    // insert accessToken to AccessToken table
                    // create new AccessToken record
                    Data_WebApi_Jquery.Models.AccessToken accessToken = new Data_WebApi_Jquery.Models.AccessToken();
                    accessToken.Created            = DateTime.Now;
                    accessToken.TokenString        = token.access_token;
                    Session["SelectedProductName"] = token.access_token;


                    try
                    {
                        using (EmpDBEntities dc = new EmpDBEntities())
                        {
                            dc.AccessTokens.Add(accessToken);
                            dc.SaveChanges();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
                // actual requests from your api follow here . . .
            }

            return(View(part7IndexView));
        }
예제 #13
0
 public NewEmployee(Employees newEmp)
 {
     db = new EmpDBEntities();
     InitializeComponent();
     dpDate.SelectedDate = DateTime.Today;
 }