public HttpResponseMessage GetAllAuthors()
        {
            HttpResponseMessage msg;

            using (JournalEntities _entities = new JournalEntities())
            {
                try
                {
                    //serialization problem instead of poco class
                    _entities.Configuration.ProxyCreationEnabled = false;
                    var authors = _entities.Authors.ToList();
                    if (authors != null)
                    {
                        msg = Request.CreateResponse(HttpStatusCode.Accepted, authors);
                        return(msg);
                    }
                    else
                    {
                        msg = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not Found");
                        return(msg);
                    }
                }
                catch (Exception ex)
                {
                    msg = Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
                    return(msg);
                }
            }
        }
Example #2
0
        public HttpResponseMessage SearchAdmins(Employee emp)
        {
            HttpResponseMessage response  = new HttpResponseMessage();
            JournalEntities     _entities = new JournalEntities();

            try
            {
                var result = _entities.Admins.FirstOrDefault(c => c.Username.ToLower() == emp.Username.ToLower() && c.Password == emp.Password);
                if (result != null)
                {
                    response = Request.CreateResponse(HttpStatusCode.OK);
                    return(response);
                }
                else
                {
                    response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
                return(response);
            }
        }
 public HttpResponseMessage Put(int ID, ABuser info)
 {
     using (JournalEntities _ent = new JournalEntities())
     {
         try
         {
             var User = _ent.ABusers.FirstOrDefault(c => c.AB_iD == ID);
             if (info == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid ID , There is no such a user with this ID = " + ID));
             }
             else
             {
                 User.Username  = info.Username;
                 User.FirstName = info.FirstName;
                 User.LastName  = info.LastName;
                 User.Pass      = info.Pass;
                 User.Phone     = info.Phone;
                 User.Company   = info.Company;
                 User.Email     = info.Email;
                 User.Picture   = info.Picture;
                 User.Articlets = info.Articlets;
                 _ent.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, info));
             }
         }
         catch (Exception ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }
        public HttpResponseMessage Put(int ID, ABuser user)
        {
            using (JournalEntities _entites = new JournalEntities())
            {
                try
                {
                    _entites.Configuration.ProxyCreationEnabled = false;

                    var User = _entites.ABusers.FirstOrDefault(c => c.AB_iD == ID);
                    if (User == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "no record with such id"));
                    }
                    else
                    {
                        User.Username  = user.Username;
                        User.FirstName = user.FirstName;
                        User.LastName  = user.LastName;
                        User.Pass      = user.Pass;
                        User.Phone     = user.Phone;
                        User.Company   = user.Company;
                        User.Email     = user.Email;
                        User.Articlets = user.Articlets;
                        _entites.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, user));
                    }
                }

                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                }
            }
        }
 public HttpResponseMessage PutBUser(string username, string password, BUser buser)
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         try
         {
             var myBuser = _entities.BUsers.FirstOrDefault(c => c.Username == username && c.Password == password);
             if (myBuser == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, " no Business User with this Password"));
             }
             else
             {
                 myBuser.Fname    = buser.Fname;
                 myBuser.Lname    = buser.Lname;
                 myBuser.Phone    = buser.Phone;
                 myBuser.Username = buser.Username;
                 myBuser.Password = buser.Password;
                 myBuser.Email    = buser.Email;
                 myBuser.Image    = buser.Image;
                 myBuser.UserType = 2;
                 _entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, " Ur Profile is Updated "));
             }
         }
         catch (Exception ex)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }
 public IEnumerable <BUser> GetBUsers()
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         return(_entities.BUsers.ToList());
     }
 }
        public HttpResponseMessage DeleteArticle(int id)
        {
            HttpResponseMessage result;

            using (JournalEntities _entities = new JournalEntities())
            {
                try
                {
                    var article = _entities.Articles.FirstOrDefault(c => c.Serial == id);
                    if (article != null)
                    {
                        _entities.Articles.Remove(article);
                        _entities.SaveChanges();
                        var msg = Request.CreateResponse(HttpStatusCode.Created, article);
                        msg.Headers.Location = new Uri(Request.RequestUri + "/" + article.Serial + "is Deleted");
                        return(msg);
                    }
                    else
                    {
                        result = Request.CreateErrorResponse(HttpStatusCode.NotFound, "The Atticle With this Serial :" + id + "Not Found");
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
                }
            }
        }
Example #8
0
 public IEnumerable <Admin> GetAdmins()
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         return(_entities.Admins.ToList());
     }
 }
 public Article GetBySerial(int id)
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         return(_entities.Articles.FirstOrDefault(c => c.Serial == id));
     }
 }
 public HttpResponseMessage PutArticle(int id, Article article)
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         try
         {
             var myArticle = _entities.Articles.FirstOrDefault(c => c.Serial == id);
             if (myArticle == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, " no Visitor User with this ID"));
             }
             else
             {
                 myArticle.Title    = article.Title;
                 myArticle.Subject  = article.Subject;
                 myArticle.Author   = article.Author;
                 myArticle.AuthorID = article.AuthorID;
                 _entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, " The Visitor User is Updated "));
             }
         }
         catch (Exception ex)
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }
Example #11
0
        public IEnumerable <Employee> GetAllUsers()
        {
            JournalEntities _entities = new JournalEntities();
            var             result    = _entities.BUsers.Select(x => new Employee
            {
                Id       = x.Id,
                Fname    = x.Fname,
                Lname    = x.Lname,
                Username = x.Username,
                Password = x.Password,
                UserType = x.UserType
            })
                                        .Concat(_entities.VUsers.Select(x => new Employee
            {
                Id       = x.Id,
                Fname    = x.Fname,
                Lname    = x.Lname,
                Username = x.Username,
                Password = x.Password,
                UserType = x.UserType
            }).Concat(_entities.Admins.Select(x => new Employee
            {
                Id       = x.Id,
                Fname    = x.Fname,
                Lname    = x.Lname,
                Username = x.Username,
                Password = x.Password,
                UserType = x.UserType
            })));

            return(result.ToList());
        }
Example #12
0
 public HttpResponseMessage PutArticle(int ID, Articlet Nart)
 {
     using (JournalEntities entities = new JournalEntities())
     {
         entities.Configuration.ProxyCreationEnabled = false;
         try
         {
             var Oart = entities.Articlets.FirstOrDefault(c => c.Article_ID == ID);
             if (Oart == null)
             {
                 return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "There is no record with such ID"));
             }
             else
             {
                 Oart.AName        = Nart.AName;
                 Oart.Article_Date = Nart.Article_Date;
                 Oart.ARtName      = Nart.ARtName;
                 Oart.Subj_Article = Nart.Subj_Article;
                 Oart.ID           = Nart.ID;
                 Oart.Type_user    = Nart.Type_user;
                 entities.SaveChanges();
                 return(Request.CreateResponse(HttpStatusCode.OK, Nart));
             }
         }
         catch (Exception ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }
        public HttpResponseMessage PutArticle(int id, PocoArticles article)
        {
            HttpResponseMessage response;

            using (JournalEntities _entities = new JournalEntities())
            {
                try
                {
                    var myArticle = _entities.Articles.FirstOrDefault(c => c.Serial == id);

                    /*var result = _entities.Articles.Select(c => new PocoArticles
                     * {
                     *  authorId = c.AuthorID
                     * }).ToList().FirstOrDefault(x => x.authorId == article.authorId);*/

                    if (myArticle == null)
                    {
                        response = Request.CreateErrorResponse(HttpStatusCode.NotFound, "the Author Id is not exist");
                        return(response);
                    }
                    else
                    {
                        var author = _entities.Authors.FirstOrDefault(c => c.Id == article.authorId);
                        myArticle.Title   = article.title;
                        myArticle.Subject = article.subject;
                        if (author != null)
                        {
                            myArticle.AuthorID = article.authorId;
                        }
                        else
                        {
                            myArticle.AuthorID = myArticle.AuthorID;
                        }
                        if (author != null && (article.authorId).GetType() == typeof(int) && (article.authorBirthYear).GetType() == typeof(int) && (article.authorWorkYears).GetType() == typeof(int) && !string.IsNullOrEmpty(article.authorFname) && !string.IsNullOrEmpty(article.authorLname))
                        {
                            author.Id          = article.authorId;
                            author.Fname       = article.authorFname;
                            author.Lname       = article.authorLname;
                            author.BirthYear   = article.authorBirthYear;
                            author.WorkYears   = article.authorWorkYears;
                            myArticle.AuthorID = article.authorId;
                            _entities.SaveChanges();
                        }
                        else
                        {
                            response = Request.CreateErrorResponse(HttpStatusCode.Forbidden, "The Author id is not exist");
                        }
                        _entities.SaveChanges();
                        response = Request.CreateResponse(HttpStatusCode.OK, " The Visitor User is Updated ");
                        return(response);
                    }
                }
                catch (Exception ex)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, ex);
                    return(response);
                }
            }
        }
Example #14
0
 public IEnumerable <Articlet> GetArticle()
 {
     using (JournalEntities entities = new JournalEntities())
     {
         entities.Configuration.ProxyCreationEnabled = false;
         return(entities.Articlets.ToList());
     }
 }
 public BUser GetBUserById(string username, string password)
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         var busers = _entities.BUsers.FirstOrDefault(c => c.Username == username && c.Password == password);
         return(busers);
     }
 }
Example #16
0
 public BUser GetBUserById(int id)
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         var busers = _entities.BUsers.FirstOrDefault(c => c.Id == id);
         return(busers);
     }
 }
        public IEnumerable <ABuser> Get()
        {
            using (JournalEntities _entites = new JournalEntities())
            {
                _entites.Configuration.ProxyCreationEnabled = false;

                return(_entites.ABusers.ToList());
            }
        }
        public ABuser Get(string ID)
        {
            using (JournalEntities entities = new JournalEntities())
            {
                entities.Configuration.ProxyCreationEnabled = false;

                return(entities.ABusers.FirstOrDefault(e => e.Username == ID));
            }
        }
        public HttpResponseMessage Post(PocoArticles article)
        {
            Article             myArticle = new Article();
            Author              myAuthor  = new Author();
            HttpResponseMessage respone   = new HttpResponseMessage();

            using (JournalEntities _entities = new JournalEntities())
            {
                try
                {
                    if (article != null)
                    {
                        myArticle.AuthorID = article.authorId;
                        myArticle.Title    = article.title;
                        myArticle.Subject  = article.subject;
                        myAuthor.Lname     = article.authorLname;
                        myAuthor.Fname     = article.authorFname;
                        myAuthor.BirthYear = article.authorBirthYear;
                        myAuthor.WorkYears = article.authorWorkYears;
                        var SID = _entities.Articles.FirstOrDefault(x => x.AuthorID == myArticle.AuthorID);
                        if (myArticle.Title != "" && myArticle != null && SID != null)
                        {
                            _entities.Articles.Add(myArticle);
                            _entities.SaveChanges();
                            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, myArticle);
                            response = Request.CreateResponse(HttpStatusCode.OK, myArticle);
                        }
                        if (myAuthor.Fname != "" && myAuthor.Fname != null && myAuthor.Lname != null && myAuthor.Lname != "" && myAuthor != null)
                        {
                            _entities.Authors.Add(myAuthor);
                            _entities.SaveChanges();
                            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, myAuthor);
                            response = Request.CreateResponse(HttpStatusCode.OK, myAuthor);
                        }
                        else
                        {
                            respone = Request.CreateErrorResponse(HttpStatusCode.Forbidden, message: "The Article Values is NULL or Authors ID is wrong");
                        }
                        return(respone);
                    }
                    else
                    {
                        return(respone = Request.CreateErrorResponse(HttpStatusCode.NoContent, "The article value is null"));
                    }
                }
                catch (Exception ex)
                {
                    return(respone = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
                }
            }
        }
Example #20
0
        public IEnumerable <Employee> GetByUserType(int usertype)
        {
            JournalEntities        _entities = new JournalEntities();
            IEnumerable <Employee> result;

            switch (usertype)
            {
            case 1:
                result = _entities.VUsers.Select(x => new Employee
                {
                    Id       = x.Id,
                    Fname    = x.Fname,
                    Lname    = x.Lname,
                    Username = x.Username,
                    Password = x.Password,
                    Email    = x.Email,
                    UserType = x.UserType
                });
                break;

            case 2:
                result = _entities.BUsers.Select(x => new Employee
                {
                    Id       = x.Id,
                    Fname    = x.Fname,
                    Lname    = x.Lname,
                    Username = x.Username,
                    Password = x.Password,
                    Email    = x.Email,
                    UserType = x.UserType
                });
                break;

            case 3:
                result = _entities.Admins.Select(x => new Employee
                {
                    Id       = x.Id,
                    Fname    = x.Fname,
                    Lname    = x.Lname,
                    Username = x.Username,
                    Password = x.Password,
                    UserType = x.UserType
                });
                break;

            default: throw new ArgumentOutOfRangeException();
            }
            return(result.ToList());
        }
Example #21
0
 public HttpResponseMessage GetArticle(string id)
 {
     using (JournalEntities entities = new JournalEntities())
     {
         entities.Configuration.ProxyCreationEnabled = false;
         var art = entities.Articlets.FirstOrDefault(c => c.ARtName == id);
         if (User == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "There is no Article with such ID"));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, art));
         }
     }
 }
        public List <PocoArticles> GetArticles()
        {
            JournalEntities _entities = new JournalEntities();

            return(_entities.Articles.Select(c => new PocoArticles
            {
                serial = c.Serial,
                title = c.Title,
                authorId = c.AuthorID,
                subject = c.Subject,
                authorFname = c.Author.Fname,
                authorLname = c.Author.Lname,
                authorBirthYear = c.Author.BirthYear,
                authorWorkYears = c.Author.WorkYears
            }).ToList());
        }
        public HttpResponseMessage Get(int id)
        {
            using (JournalEntities _entites = new JournalEntities())
            {
                _entites.Configuration.ProxyCreationEnabled = false;

                var user = _entites.ABusers.FirstOrDefault(c => c.AB_iD == id);
                if (user == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "This user is not found"));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, user));
                }
            }
        }
 public HttpResponseMessage Post(Article article)
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         try
         {
             _entities.Articles.Add(article);
             _entities.SaveChanges();
             HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, article);
             response.Headers.Location = new Uri(Request.RequestUri + "/" + article.Serial);
             return(response);
         }
         catch (Exception ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }
Example #25
0
        public IEnumerable <ABuser> Get()
        {
            using (JournalEntities _entites = new JournalEntities())
            {
                _entites.Configuration.ProxyCreationEnabled = false;
                List <ABuser> admins = new List <ABuser>();
                var           users  = _entites.ABusers.ToList();
                foreach (ABuser admin in users)
                {
                    if (admin.Type_user == "User")
                    {
                        admins.Add(admin);
                    }
                }

                return(admins);
            }
        }
Example #26
0
 public HttpResponseMessage Delete(int ID)
 {
     using (JournalEntities entities = new JournalEntities())
     {
         entities.Configuration.ProxyCreationEnabled = false;
         var article = entities.Articlets.FirstOrDefault(c => c.Article_ID == ID);
         if (entities == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "There is no record with such ID"));
         }
         else
         {
             entities.Articlets.Remove(article);
             entities.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
     }
 }
 public HttpResponseMessage Delete(int id)
 {
     using (JournalEntities _entites = new JournalEntities())
     {
         _entites.Configuration.ProxyCreationEnabled = false;
         var user = _entites.ABusers.FirstOrDefault(aa => aa.AB_iD == id);
         if (user == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "This user is not found"));
         }
         else
         {
             _entites.ABusers.Remove(user);
             _entites.SaveChanges();
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
     }
 }
Example #28
0
        public HttpResponseMessage PostLast(int usertype, User emp)
        {
            HttpResponseMessage response = new HttpResponseMessage();

            using (JournalEntities _entities = new JournalEntities())
            {
                if (usertype == 2)
                {
                    BUser buser = new BUser();
                    buser.Id       = emp.Id;
                    buser.Fname    = emp.Fname;
                    buser.Lname    = emp.Lname;
                    buser.Phone    = emp.Password;
                    buser.Email    = emp.Email;
                    buser.Username = emp.Username;
                    buser.Password = emp.Password;
                    buser.UserType = 2;
                    _entities.BUsers.Add(buser);
                    _entities.SaveChanges();
                    response = Request.CreateResponse(HttpStatusCode.OK, "The BUser is added");
                    return(response);
                }
                else if (usertype == 3)
                {
                    Admin admin = new Admin();
                    admin.Id       = emp.Id;
                    admin.Fname    = emp.Fname;
                    admin.Lname    = emp.Lname;
                    admin.Phone    = emp.Phone;
                    admin.Username = emp.Username;
                    admin.Password = emp.Password;
                    admin.UserType = 3;
                    _entities.Admins.Add(admin);
                    _entities.SaveChanges();
                    response = Request.CreateResponse(HttpStatusCode.OK, "The Admin is added");
                    return(response);
                }
                else
                {
                    response = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not Added");
                    return(response);
                }
            }
        }
 public HttpResponseMessage DeleteArticle(int id)
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         try
         {
             var article = _entities.Articles.FirstOrDefault(c => c.Serial == id);
             _entities.Articles.Remove(article);
             _entities.SaveChanges();
             var msg = Request.CreateResponse(HttpStatusCode.Created, article);
             msg.Headers.Location = new Uri(Request.RequestUri + "/" + article.Serial + "is Deleted");
             return(msg);
         }
         catch (Exception ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }
 public HttpResponseMessage DeleteBUser(int id)
 {
     using (JournalEntities _entities = new JournalEntities())
     {
         try
         {
             var buser = _entities.BUsers.FirstOrDefault(c => c.Id == id);
             _entities.BUsers.Remove(buser);
             _entities.SaveChanges();
             var msg = Request.CreateResponse(HttpStatusCode.Created, buser);
             msg.Headers.Location = new Uri(Request.RequestUri + "/" + buser.Id + "is Deleted");
             return(msg);
         }
         catch (Exception ex)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
         }
     }
 }