コード例 #1
0
        public UserAuth GenerateToken(int UserId, string Password)
        {
            string token = Guid.NewGuid().ToString();
            //DateTime issuedOn = DateTime.Now;
            DateTime expiredOn   = DateTime.Now.AddSeconds(1000000);
            var      tokendomain = new UserAuth
            {
                UserId     = UserId,
                Password   = Password,
                AuthToken  = token,
                ExpiryTime = expiredOn
            };

            UserAuth       ua = new UserAuth();
            BasicsEntities sd = new BasicsEntities();

            ua = sd.UserAuths.Where(x => x.UserId == UserId & x.Password == Password).FirstOrDefault();
            if (ua.UserId != null)
            {
                ua.AuthToken = tokendomain.AuthToken;
                //ua.IssuedOn = tokendomain.IssuedOn;
                ua.ExpiryTime = tokendomain.ExpiryTime;
                sd.SaveChanges();
            }
            return(tokendomain);
        }
コード例 #2
0
        public IHttpActionResult DeleteEmployee(int Id)
        {
            BasicsEntities Db  = new BasicsEntities();
            var            del = (from Item in Db.Employees where Item.Id == Id select Item).FirstOrDefault();

            Db.Employees.Remove(del);
            //var EmpList = Db.Employees.Where(e => e.Id == Id).FirstOrDefault();
            //Db.Entry(employee).State = System.Data.Entity.EntityState.Deleted;
            Db.SaveChanges();
            return(Ok("Delete successfull!!"));
        }
コード例 #3
0
        public IHttpActionResult PutEmployee(Employee employee)
        {
            BasicsEntities Db = new BasicsEntities();

            var EmpList = Db.Employees.Where(e => e.Id == employee.Id).FirstOrDefault();

            EmpList.Name  = employee.Name;
            EmpList.Email = employee.Email;
            EmpList.Phone = employee.Phone;
            Db.SaveChanges();
            return(Ok("Put successfull!!"));
        }
コード例 #4
0
        public IHttpActionResult PostEmployee(Employee employee)
        {
            BasicsEntities Db = new BasicsEntities();

            Db.Employees.Add(new Employee()
            {
                Name  = employee.Name,
                Email = employee.Email,
                Phone = employee.Phone
            });
            Db.SaveChanges();
            return(Ok("Post successfull!!"));
        }