Пример #1
0
        public bool AddTweet(Tweet tweetObj)
        {
            using (FSDEntities dbContext = new FSDEntities())
            {
                try
                {
                    dbContext.Tweets.Add(tweetObj);
                    dbContext.SaveChanges();
                    return(true);
                }

                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
Пример #2
0
        public List <Person> SearchtoFollow(string userId)
        {
            List <Person> follwers = new List <Person>();

            using (FSDEntities dbContext = new FSDEntities())
            {
                try
                {
                    List <FollowersEntity> ent = new List <FollowersEntity>();

                    follwers = dbContext.People.Where(x => x.user_id != userId).ToList();

                    return(follwers);
                }

                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }
        }
Пример #3
0
        public IHttpActionResult UpdateTask(Task task)
        {
            try
            {
                using (var fsd = new FSDEntities())
                {
                    var  insertItem = fsd.Set <Task>();
                    Task present    = new Task();
                    present = insertItem.Where(x => x.task_id == task.task_id).First();

                    present.Start_Date = task.Start_Date;
                    present.End_Date   = task.End_Date;
                    present.TaskName   = task.TaskName;
                    present.Status     = task.Status;

                    present.Status = "Completed";
                    fsd.SaveChanges();
                    return(Ok());
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
Пример #4
0
 public Tweet EditTweet(int id)
 {
     using (FSDEntities dbContext = new FSDEntities())
     {
         var tweet = (Tweet)dbContext.Tweets.Where(x => x.tweet_id == id).First();
         return(tweet);
     }
 }
Пример #5
0
 public Person ManageAccount(string userid)
 {
     using (FSDEntities dbContext = new FSDEntities())
     {
         Person present = dbContext.People.Where(x => x.user_id == userid).First();
         return(present);
     }
 }
Пример #6
0
        public List <Tweet> ManageTweets(string userid)
        {
            List <Tweet> tweets = new List <Tweet>();

            using (FSDEntities dbContext = new FSDEntities())
            {
                tweets = dbContext.Tweets.Where(x => x.user_id == userid).ToList();
            }
            return(tweets);
        }
Пример #7
0
        public ActionResult ManageAccounts()
        {
            if (Session["UserId"] != null)
            {
                string userid = Session["UserId"].ToString();
                using (FSDEntities dbContext = new FSDEntities())
                {
                    Person present = dbContext.People.Where(x => x.user_id == userid).First();
                    return(View(present));
                }
            }

            return(RedirectToAction("Login", "Account"));
        }
Пример #8
0
        public List <Tweet> FetchTweetsForuser(string userid)
        {
            List <Tweet> tweets = new List <Tweet>();

            using (FSDEntities dbContext = new FSDEntities())
            {
                Person present = dbContext.People.Where(x => x.user_id == userid).First();
                foreach (Person p in present.People)
                {
                    tweets.AddRange(dbContext.Tweets.Where(x => x.user_id == p.user_id).ToList());
                }
            }
            return(tweets);
        }
Пример #9
0
 public IHttpActionResult GetTasks()
 {
     try
     {
         using (
             var fsd = new FSDEntities())
         {
             List <Task> items = fsd.Set <Task>().ToList();
             return(Ok(items));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #10
0
 public IHttpActionResult GetUserById(int identity)
 {
     try
     {
         using (
             var fsd = new FSDEntities())
         {
             List <User> items = fsd.Set <User>().ToList();
             return(Ok(items.Where(x => x.user_id == identity).First()));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #11
0
        public ActionResult EditTweet(int id)
        {
            if (Session["UserId"] != null)
            {
                //Tweet tweet = new Tweet();

                using (FSDEntities dbContext = new FSDEntities())
                {
                    var tweet = (Tweet)dbContext.Tweets.Where(x => x.tweet_id == id).First();
                    return(View(tweet));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
Пример #12
0
 public IHttpActionResult DeleteProject(int identity)
 {
     try
     {
         using (var fsd = new FSDEntities())
         {
             var insertItem = fsd.Set <Project>();
             insertItem.Remove(insertItem.Where(x => x.Project_ID == identity).First());
             fsd.SaveChanges();
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #13
0
        public Person Authenticateuser(UserAcccount user)
        {
            Person p = new Person();

            using (FSDEntities dbContext = new FSDEntities())
            {
                try
                {
                    p = dbContext.People.Single(x => x.user_id == user.user_id && x.password == user.password);
                }
                catch
                {
                    p = null;
                }
            }
            return(p);
        }
Пример #14
0
 public bool DeleteTweet(int id)
 {
     try
     {
         using (FSDEntities dbContext = new FSDEntities())
         {
             var PresntTweet = (Tweet)dbContext.Tweets.Where(x => x.tweet_id == id).First();
             dbContext.Tweets.Remove(PresntTweet);
             dbContext.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Пример #15
0
        public ActionResult ManageAccounts(Person updatePerson)
        {
            if (Session["UserId"] != null)
            {
                string userid = Session["UserId"].ToString();
                using (FSDEntities dbContext = new FSDEntities())
                {
                    Person present = dbContext.People.Where(x => x.user_id == userid).First();
                    present.email    = updatePerson.email;
                    present.fullName = updatePerson.fullName;
                    present.active   = updatePerson.active;
                    dbContext.SaveChanges();
                    return(RedirectToAction("LoggedIn", "Account"));
                }
            }

            return(RedirectToAction("Login", "Account"));
        }
Пример #16
0
        public bool UpdateTweet(Tweet tweet)
        {
            try
            {
                using (FSDEntities dbContext = new FSDEntities())
                {
                    var PresntTweet = (Tweet)dbContext.Tweets.Where(x => x.tweet_id == tweet.tweet_id).First();
                    PresntTweet.message = tweet.message;
                    dbContext.SaveChanges();
                    return(true);
                }
            }

            catch
            {
                return(false);
            }
        }
Пример #17
0
        public IHttpActionResult Put(OrderViewModel order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }


            using (var ctx = new FSDEntities())
            {
                var existingPo = ctx.POMASTERs.Where(s => s.PONO.Equals(order.PoNo)).FirstOrDefault <POMASTER>();


                if (existingPo != null)
                {
                    existingPo.PODATE = order.PoDate;
                    ctx.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }


                foreach (OrderDetailsViewModel item in order.OrderDetails)
                {
                    var existingItem = ctx.ITEMs.Where(s => s.ITCODE.Equals(item.ItCode)).FirstOrDefault <ITEM>();
                    if (existingItem != null)
                    {
                        existingItem.ITRATE = item.ItRate;
                    }

                    var existingChildPo = ctx.PODETAILs.Where(s => s.PONO.Equals(item.CPoNo)).FirstOrDefault <PODETAIL>();

                    if (existingChildPo != null)
                    {
                        existingChildPo.QTY = item.Qty;
                    }
                    ctx.SaveChanges();
                }
            }

            return(Ok());
        }
Пример #18
0
 public IHttpActionResult AddProject(Project proj)
 {
     try
     {
         using (var fsd = new FSDEntities())
         {
             var insertItem = fsd.Set <Project>();
             insertItem.Add(new Project {
                 ProjectName = proj.ProjectName, StartDate = proj.StartDate, EndDate = proj.EndDate, priority = proj.priority
             });
             fsd.SaveChanges();
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #19
0
 public IHttpActionResult AddParentTask(ParentTask proj)
 {
     try
     {
         using (var fsd = new FSDEntities())
         {
             var insertItem = fsd.Set <ParentTask>();
             insertItem.Add(new ParentTask {
                 parent_task = proj.parent_task
             });
             fsd.SaveChanges();
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #20
0
 public IHttpActionResult AddTask(Task proj)
 {
     try
     {
         using (var fsd = new FSDEntities())
         {
             var insertItem = fsd.Set <Task>();
             insertItem.Add(new Task {
                 parent_id = proj.parent_id, project_ID = proj.project_ID, TaskName = proj.TaskName, Start_Date = proj.Start_Date, End_Date = proj.End_Date, priority = proj.priority
             });
             fsd.SaveChanges();
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #21
0
 public IHttpActionResult AddUser(User usr)
 {
     try
     {
         using (var fsd = new FSDEntities())
         {
             var insertItem = fsd.Set <User>();
             insertItem.Add(new User {
                 FirstName = usr.FirstName.TrimEnd(), Lastname = usr.Lastname.TrimEnd(), Employee_ID = usr.Employee_ID.TrimEnd()
             });
             fsd.SaveChanges();
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #22
0
        public ActionResult DeleteTweet(int id)
        {
            if (Session["UserId"] != null)
            {
                //Tweet tweet = new Tweet();

                using (FSDEntities dbContext = new FSDEntities())
                {
                    var PresntTweet = (Tweet)dbContext.Tweets.Where(x => x.tweet_id == id).First();
                    dbContext.Tweets.Remove(PresntTweet);
                    dbContext.SaveChanges();
                    return(RedirectToAction("ManageTweets"));
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Пример #23
0
        public ActionResult AddToFollow(string id)
        {
            Person presentPerson      = new Person();
            Person toBeFollowedPerson = new Person();

            if (Session["UserId"] != null)
            {
                using (FSDEntities dbContext = new FSDEntities())
                {
                    try
                    {
                        List <FollowersEntity> ent = new List <FollowersEntity>();
                        string userId = Session["UserId"].ToString();
                        toBeFollowedPerson = dbContext.People.Where(x => x.user_id == id).FirstOrDefault();
                        dbContext.People.Where(x => x.user_id == userId).First().People.Add(toBeFollowedPerson);
                        //presentPerson.People.Add(toBeFollowedPerson);
                        dbContext.SaveChanges();
                        return(RedirectToAction("ManageFollowing"));
                    }

                    catch (DbEntityValidationException ex)
                    {
                        // Retrieve the error messages as a list of strings.
                        var errorMessages = ex.EntityValidationErrors
                                            .SelectMany(x => x.ValidationErrors)
                                            .Select(x => x.ErrorMessage);

                        // Join the list to a single string.
                        var fullErrorMessage = string.Join("; ", errorMessages);

                        // Combine the original exception message with the new one.
                        var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                        // Throw a new DbEntityValidationException with the improved exception message.
                        throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }
        }
Пример #24
0
 public bool UpdateAccount(Person updatePerson, string userid)
 {
     try
     {
         using (FSDEntities dbContext = new FSDEntities())
         {
             Person present = dbContext.People.Where(x => x.user_id == userid).First();
             present.email    = updatePerson.email;
             present.fullName = updatePerson.fullName;
             present.active   = updatePerson.active;
             dbContext.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Пример #25
0
        // GET api/Order
        public IHttpActionResult GetAllorders()
        {
            IList <OrderViewModel> orders = null;

            db.POMASTERs.Include(c => c.SUPPLIER);
            db.PODETAILs.Include(c => c.ITEM);
            db.POMASTERs.Include(db => db.PODETAILs);



            using (var ctx = new FSDEntities())
            {
                orders = ctx.POMASTERs.Select(s => new OrderViewModel()
                {
                    PoNo         = s.PONO,
                    PoDate       = s.PODATE,
                    SupLNo       = s.SUPLNO,
                    SuplName     = s.SUPPLIER.SUPLNAME,
                    SuplAddr     = s.SUPPLIER.SUPLADDR,
                    OrderDetails = ctx.PODETAILs.Where(s1 => s1.PONO == s.PONO).Select(s1 => new OrderDetailsViewModel()
                    {
                        ItCode = s1.ITCODE,
                        CPoNo  = s1.PONO,
                        ItDesc = s1.ITEM.ITDESC,
                        Qty    = s1.QTY,
                        ItRate = s1.ITEM.ITRATE
                    }

                                                                                       ).ToList <OrderDetailsViewModel>()
                }

                                              ).ToList <OrderViewModel>();
            }

            if (orders.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(orders));
        }
Пример #26
0
 public IHttpActionResult UpdateUser(User usr)
 {
     try
     {
         using (var fsd = new FSDEntities())
         {
             var  insertItem = fsd.Set <User>();
             User present    = new User();
             present             = insertItem.Where(x => x.user_id == usr.user_id).First();
             present.FirstName   = usr.FirstName;
             present.Lastname    = usr.Lastname;
             present.Employee_ID = usr.Employee_ID;
             fsd.SaveChanges();
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #27
0
 public IHttpActionResult UpdateProject(Project proj)
 {
     try
     {
         using (var fsd = new FSDEntities())
         {
             var     insertItem = fsd.Set <Project>();
             Project present    = new Project();
             present             = insertItem.Where(x => x.Project_ID == proj.Project_ID).First();
             present.ProjectName = proj.ProjectName;
             present.StartDate   = proj.StartDate;
             present.EndDate     = proj.EndDate;
             present.priority    = proj.priority;
             fsd.SaveChanges();
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.ToString()));
     }
 }
Пример #28
0
        public bool AddToFollow(string userId)
        {
            Person presentPerson      = new Person();
            Person toBeFollowedPerson = new Person();

            using (FSDEntities dbContext = new FSDEntities())
            {
                try
                {
                    List <FollowersEntity> ent = new List <FollowersEntity>();

                    toBeFollowedPerson = dbContext.People.Where(x => x.user_id == userId).FirstOrDefault();
                    dbContext.People.Where(x => x.user_id == userId).First().People.Add(toBeFollowedPerson);
                    //presentPerson.People.Add(toBeFollowedPerson);
                    dbContext.SaveChanges();
                    return(true);
                }

                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                    return(false);
                }
            }
        }
Пример #29
0
        public IHttpActionResult Delete(string Pid)
        {
            using (var ctx = new FSDEntities())
            {
                if (Pid.Length <= 0)
                {
                    return(BadRequest("Not a valid PO Order id"));
                }

                var orderdetails = ctx.PODETAILs.Where(s => s.PONO.Equals(Pid)).FirstOrDefault <PODETAIL>();
                if (orderdetails != null)
                {
                    ctx.Entry(orderdetails).State = System.Data.Entity.EntityState.Deleted;
                    ctx.SaveChanges();
                }
                var orderPo = ctx.POMASTERs.Where(s => s.PONO.Equals(Pid)).FirstOrDefault <POMASTER>();
                if (orderPo != null)
                {
                    ctx.Entry(orderPo).State = System.Data.Entity.EntityState.Deleted;
                    ctx.SaveChanges();
                }
            }
            return(Ok());
        }
Пример #30
0
 public PersonService()
 {
     contextEntities = new FSDEntities();
 }