예제 #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 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()));
            }
        }
예제 #3
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());
        }
예제 #4
0
 public void SavePerson(Person person)
 {
     person.active  = true;
     person.user_id = person.email;
     person.joined  = DateTime.Now;
     contextEntities.People.Add(person);
     contextEntities.SaveChanges();
 }
예제 #5
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());
        }
예제 #6
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()));
     }
 }
예제 #7
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);
     }
 }
예제 #8
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"));
        }
예제 #9
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);
            }
        }
예제 #10
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()));
     }
 }
예제 #11
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()));
     }
 }
예제 #12
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()));
     }
 }
예제 #13
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()));
     }
 }
예제 #14
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"));
            }
        }
예제 #15
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"));
            }
        }
예제 #16
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);
     }
 }
예제 #17
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()));
     }
 }
예제 #18
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()));
     }
 }
예제 #19
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);
                }
            }
        }
예제 #20
0
        public IHttpActionResult PostNewOrder(OrderViewModel order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            string supNo = null;
            string itNo  = null;
            string PoNo  = null;


            using (var ctx = new FSDEntities())
            {
                var existingSupplier = ctx.SUPPLIERs.Where(s => s.SUPLNAME.Equals(order.SuplName)).FirstOrDefault <SUPPLIER>();


                if (existingSupplier != null)
                {
                    supNo = existingSupplier.SUPLNO;
                    existingSupplier.SUPLADDR = order.SuplAddr;
                }
                else
                {
                    var SupNumberList = from x in ctx.SUPPLIERs
                                        select new
                    {
                        sublstring = x.SUPLNO.Substring(1)
                    };

                    var MaxSupNum = SupNumberList.Max(c => c.sublstring);

                    var supMaxNo = Convert.ToInt32(MaxSupNum) + 1;
                    supNo = "S" + supMaxNo.ToString("D3");

                    ctx.SUPPLIERs.Add(new SUPPLIER()
                    {
                        SUPLNO   = supNo,
                        SUPLNAME = order.SuplName,
                        SUPLADDR = order.SuplAddr
                    });
                }
                ctx.SaveChanges();
            }



            using (var ctx = new FSDEntities())
            {
                var PoNumberList = from x in ctx.POMASTERs
                                   select new
                {
                    Postring = x.PONO.Substring(1)
                };

                var MaxPoNum = PoNumberList.Max(c => c.Postring);

                var PoMaxNo = Convert.ToInt32(MaxPoNum) + 1;
                PoNo = "P" + PoMaxNo.ToString("D3");

                ctx.POMASTERs.Add(new POMASTER()
                {
                    PONO   = PoNo,
                    PODATE = order.PoDate,
                    SUPLNO = supNo
                });

                ctx.SaveChanges();
            }



            using (var ctx = new FSDEntities())
            {
                foreach (OrderDetailsViewModel item in order.OrderDetails)
                {
                    var existingItem = ctx.ITEMs.Where(s => s.ITDESC.Equals(item.ItDesc)).FirstOrDefault <ITEM>();
                    if (existingItem != null)
                    {
                        itNo = existingItem.ITCODE;
                        existingItem.ITRATE = item.ItRate;
                    }
                    else
                    {
                        var ItemNumberList = from x in ctx.ITEMs
                                             select new
                        {
                            itemstring = x.ITCODE.Substring(1)
                        };

                        var MaxItemNum = ItemNumberList.Max(c => c.itemstring);

                        var itMaxNo = Convert.ToInt32(MaxItemNum) + 1;
                        itNo = "I" + itMaxNo.ToString("D3");

                        ctx.ITEMs.Add(new ITEM()
                        {
                            ITCODE = itNo,
                            ITDESC = item.ItDesc,
                            ITRATE = item.ItRate
                        });
                    }


                    ctx.PODETAILs.Add(new PODETAIL()
                    {
                        PONO   = PoNo,
                        ITCODE = itNo,
                        QTY    = item.Qty
                    });


                    ctx.SaveChanges();
                }
            }

            return(Ok());
        }