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); } } }
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); } } }
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())); } }
public Tweet EditTweet(int id) { using (FSDEntities dbContext = new FSDEntities()) { var tweet = (Tweet)dbContext.Tweets.Where(x => x.tweet_id == id).First(); return(tweet); } }
public Person ManageAccount(string userid) { using (FSDEntities dbContext = new FSDEntities()) { Person present = dbContext.People.Where(x => x.user_id == userid).First(); return(present); } }
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); }
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")); }
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); }
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())); } }
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())); } }
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")); } }
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())); } }
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); }
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); } }
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")); }
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); } }
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()); }
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())); } }
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())); } }
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())); } }
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())); } }
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")); } }
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")); } }
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); } }
// 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)); }
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())); } }
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())); } }
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); } } }
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()); }
public PersonService() { contextEntities = new FSDEntities(); }