public HttpResponseMessage Delete(string id)
        {
            using (TeloipEntities db = new TeloipEntities())
            {
                var entity = db.Users.FirstOrDefault(e => e.Id == id);
                if (entity == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User with id=" + id.ToString() + "not found to delete"));
                }
                else
                {
                    db.Users.Remove(entity);
                    db.SaveChanges();

                    //Update Log
                    log.Action = "DeleteUser" + entity.Id;

                    log.OldData = "FirstName: \"" + entity.FirstName + "\"|" + "LastName: \"" + entity.LastName + "\"|" + "EmailAddress: \"" + entity.EmailAddress + "\"|" + "ActiveStatus: " + entity.ActiveStatus + "|" + "LockStatus: " + entity.LockStatus;
                    UpdateLog(log);


                    return(Request.CreateResponse(HttpStatusCode.OK));
                }
            }
        }
        private void UpdateLog(AuditLog al)
        {
            al.EmailAddress   = baa.GetUserName();
            al.ActionDateTime = DateTime.Now;

            using (TeloipEntities db = new TeloipEntities())
            {
                db.AuditLogs.Add(log);
                db.SaveChanges();
            }
        }
        public HttpResponseMessage Put([FromBody] User user)
        {
            using (TeloipEntities db = new TeloipEntities())
            {
                try
                {
                    var usercheck = db.Users.SqlQuery("Select * from users where emailaddress='" + user.EmailAddress + "' and id!='" + user.Id + "'").FirstOrDefault <User>();

                    if (usercheck == null)
                    {
                        var entity = db.Users.FirstOrDefault(e => e.Id == user.Id);
                        if (entity == null)
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "User with mentioned id not found to update"));
                        }
                        else
                        {
                            log.OldData         = "FirstName: \"" + entity.FirstName + "\"|" + "LastName: \"" + entity.LastName + "\"|" + "EmailAddress: \"" + entity.EmailAddress + "\"|" + "ActiveStatus: " + entity.ActiveStatus + "|" + "LockStatus: " + entity.LockStatus;
                            entity.FirstName    = user.FirstName;
                            entity.LastName     = user.LastName;
                            entity.EmailAddress = user.EmailAddress;
                            //entity.Password = EncodePasswordToBase64(user.Password);
                            entity.Password     = user.Password;
                            entity.ActiveStatus = user.ActiveStatus;
                            entity.LockStatus   = user.LockStatus;
                            db.SaveChanges();

                            //Update Log
                            log.Action = "UpdateUser" + entity.Id;

                            log.NewData = "FirstName: \"" + entity.FirstName + "\"|" + "LastName: \"" + entity.LastName + "\"|" + "EmailAddress: \"" + entity.EmailAddress + "\"|" + "ActiveStatus: " + entity.ActiveStatus + "|" + "LockStatus: " + entity.LockStatus;

                            UpdateLog(log);

                            return(Request.CreateResponse(HttpStatusCode.OK, entity));
                        }
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.Found, "Email ID already registered with another user"));
                    }
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                }
            }
        }
        public HttpResponseMessage Post([FromBody] User user)
        {
            using (TeloipEntities db = new TeloipEntities())
            {
                //return db.Users.FirstOrDefault(e => e.Id == id);

                var entity = db.Users.FirstOrDefault(e => e.EmailAddress == user.EmailAddress);
                if (entity == null)
                {
                    try
                    {
                        user.Id = System.Guid.NewGuid().ToString();
                        //user.Password = EncodePasswordToBase64(user.Password);
                        db.Users.Add(user);
                        db.SaveChanges();

                        //Update Log
                        log.Action  = "CreateNewUserwithID=" + user.Id;
                        log.NewData = "FirstName: \"" + user.FirstName + "\"|" + "LastName: \"" + user.LastName + "\"|" + "EmailAddress: \"" + user.EmailAddress + "\"|" + "ActiveStatus: " + user.ActiveStatus + "|" + "LockStatus: " + user.LockStatus;
                        log.OldData = "";
                        UpdateLog(log);

                        var message = Request.CreateResponse(HttpStatusCode.Created, user);
                        message.Headers.Location = new Uri(Request.RequestUri + user.Id.ToString());
                        return(message);
                    }
                    catch (Exception ex)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                    }
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.Found, "Email ID Already Exist"));
                }
            }
        }