public static IQueryable <TO_DO> FilterForAdmin(DateFilterModel d) { ToDoEntities br = new ToDoEntities(); var result = br.TO_DO.AsQueryable(); if (d != null) { if (d.Deadline != 3) { if (d.Deadline == 1) { result = result.Where(x => x.Deadline > DateTime.Now); } else if (d.Deadline == 0) { result = result.Where(x => x.Deadline < DateTime.Now); } } if (!string.IsNullOrEmpty(d.UserId)) { var userid = Guid.Parse(d.UserId); result = result.Where(x => x.UserID.Equals(userid)); } if (!string.IsNullOrEmpty(d.Name)) { result = result.Where(x => x.Name.Equals(d.Name)); } if (!string.IsNullOrEmpty(d.Status)) { byte n = Convert.ToByte(d.Status); result = result.Where(x => x.Status.Equals(n)); } } return(result); }
public List <User> GetAllUsers() { using (ToDoEntities toDo = new ToDoEntities()) { return(toDo.Users.ToList()); } }
public static IQueryable <TO_DO> Filter(DateFilterModel d) { ToDoEntities br = new ToDoEntities(); var usrid = Guid.Parse(Membership.GetUser().ProviderUserKey.ToString()); var result = br.TO_DO.Where(x => x.UserID == usrid).AsQueryable(); if (d != null) { if (d.Deadline != 3) { if (d.Deadline == 1) { result = result.Where(x => x.Deadline > DateTime.Now); } else if (d.Deadline == 0) { result = result.Where(x => x.Deadline < DateTime.Now); } } if (!string.IsNullOrEmpty(d.Name)) { result = result.Where(x => x.Name.Equals(d.Name)); } if (!string.IsNullOrEmpty(d.Status)) { byte n = Convert.ToByte(d.Status); result = result.Where(x => x.Status.Equals(n)); } } return(result); }
public void InsertUser(User user) { using (ToDoEntities toDo = new ToDoEntities()) { toDo.Users.Add(user); toDo.SaveChanges(); } }
public ActionResult UpdateToDo(string To_Do_ID, string Status) { using (var context = new ToDoEntities()) { context.UPDATE_TO_DO(Convert.ToInt32(To_Do_ID), Convert.ToByte(Status)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult CreateToDo(TO_DO toDo) { using (var context = new ToDoEntities()) { context.ADD_TO_DO(toDo.Name, toDo.Description, toDo.Deadline, toDo.Status, toDo.UserID); TempData["Message"] = "Success"; } return(RedirectToAction("ToDoList", "Admin")); }
public ActionResult UpdateItem(string Item_ID, string Status) { using (var context = new ToDoEntities()) { context.UPDATE_STATUS_ITEM(Convert.ToByte(Status), Convert.ToInt32(Item_ID)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteItem(string Item_ID) { using (var context = new ToDoEntities()) { context.DELETE_ITEM(Convert.ToInt32(Item_ID)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult SaveItem(string Item_Description, string To_Do_ID) { using (var context = new ToDoEntities()) { context.ADD_ITEM(Item_Description, 1, Convert.ToInt32(To_Do_ID)); } return(Json(true, JsonRequestBehavior.AllowGet)); }
public ActionResult DeleteToDo() { int id = Convert.ToInt32(Request.QueryString["id"].ToString()); using (var context = new ToDoEntities()) { context.DELETE_ITEM_TO_DO(id); context.DELETE_TO_DO(id); } return(RedirectToAction("ToDoList", "Admin")); }
public void SaveItem() { AdminController controller = new AdminController(); string description = "Item 1"; string ToDoId = "2"; ViewResult result = controller.SaveItem(description, ToDoId) as ViewResult; ToDoEntities tden = new ToDoEntities(); long ID = long.Parse(ToDoId); var expecting = tden.ITEMs.Where(x => x.Item_Description == description && x.To_Do_ID == ID).FirstOrDefault(); Assert.IsNotNull(expecting); }
public ActionResult CreateToDo(TO_DO toDo) { string usrname = User.Identity.Name; using (var context = new ToDoEntities()) { var usrid = Guid.Parse(Membership.GetUser().ProviderUserKey.ToString()); context.ADD_TO_DO(toDo.Name, toDo.Description, toDo.Deadline, toDo.Status, usrid); TempData["Message"] = "Success"; } return(RedirectToAction("ToDoList", "Home")); }
public bool IsUserRegistered(string username) { using (ToDoEntities toDo = new ToDoEntities()) { bool isRegistered = false; foreach (var user in toDo.Users) { if (user.Username == username) { isRegistered = true; } } return(isRegistered); } }
public bool IsUserLogged(string username, string password) { using (ToDoEntities toDo = new ToDoEntities()) { bool isLogged = false; foreach (var user in toDo.Users) { if (user.Username == username && user.Password == password) { isLogged = true; } } return(isLogged); } }
public IHttpActionResult Delete(Task deleteTask) { using (var dbCtx = new ToDoEntities()) { // Druga varijanta: // dbCtx.Entry(deleteTask).State = System.Data.Entity.EntityState.Deleted; var x = dbCtx.Tasks.Single(p => p.ID == deleteTask.ID); dbCtx.Tasks.Remove(x); dbCtx.SaveChanges(); } return(Ok("Successfully delete task!")); }
public void Register() { // Arrange LoginController controller = new LoginController(); User model = new User { UserName = "******", Password = "******", Email = "*****@*****.**" }; ToDoEntities td = new ToDoEntities(); ViewResult result = controller.Register(model) as ViewResult; MembershipUser user = Membership.GetUser(model.UserName); var Expecting = td.aspnet_Users.Find(user.ProviderUserKey); // Assert Assert.IsNotNull(Expecting); }
public IHttpActionResult Add(Task newTask) { using (var dbCtx = new ToDoEntities()) { //Add newtask object into Task DBset dbCtx.Tasks.Add(newTask); // Druga varijanta: // dbCtx.Entry(newTask).State = System.Data.Entity.EntityState.Added; // call SaveChanges method to save Task into database dbCtx.SaveChanges(); } return(Json(newTask)); }
public void CreateToDo() { // Arrange AdminController controller = new AdminController(); TO_DO td = new TO_DO { Name = "Example ToDo", Description = "Example Description", Deadline = new DateTime(2019, 06, 25), Status = 1, UserID = Guid.Parse("0797F007-813A-455C-BF42-5D8BE5DE34A7") }; // Act ViewResult result = controller.CreateToDo(td) as ViewResult; ToDoEntities tden = new ToDoEntities(); var expecting = tden.TO_DO.Where(x => x.Name == td.Name && x.Description == td.Description).FirstOrDefault(); // Assert Assert.IsNotNull(expecting); }
public IHttpActionResult Update(Task task) { using (var dbCtx = new ToDoEntities()) { // Druga varijanta: //dbCtx.Entry(task).State = System.Data.Entity.EntityState.Modified; var x = dbCtx.Tasks.Single(p => p.ID == task.ID); //dbCtx.Tasks.Attach(x); x.ID = task.ID; x.Title = task.Title; x.CreatedDate = task.CreatedDate; x.Description = task.Description; x.State = task.State; x.DeadlineDate = task.DeadlineDate; dbCtx.SaveChanges(); } return(Ok("Successfully update task!")); }