コード例 #1
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         if (ModelState.IsValid)
         {
             //first create a new object using form collection
             //then pass the object to model to create.
             TODOItem newTODOItem = new TODOItem();
             newTODOItem.Description = collection["Description"];
             newTODOItem.Status      = collection["Status"];
             //Lets invoke DB entity
             using (TODOITEMEntity tODOITEMEntity = new TODOITEMEntity())
             {
                 tODOITEMEntity.TODOItems.Add(newTODOItem);
                 tODOITEMEntity.SaveChanges();
                 return(RedirectToAction("Index"));
             }
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         //Handle catch situation
         return(View());
     }
 }
コード例 #2
0
        public async Task SaveTodoItemAsync(TODOItem item, bool isNewItem)
        {
            var uri = new Uri(string.Format(Constants.TodoItemsUrl, string.Empty));

            try
            {
                var json    = JsonConvert.SerializeObject(item);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                HttpResponseMessage response = null;
                if (isNewItem)
                {
                    response = await _client.PostAsync(uri, content);
                }
                else
                {
                    response = await _client.PutAsync(uri, content);
                }

                if (response.IsSuccessStatusCode)
                {
                    Debug.WriteLine(@"\tTodoItem successfully saved.");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(@"\tERROR {0}", ex.Message);
            }
        }
コード例 #3
0
 public void Insert(TODOItem item)
 {
     using (TODOContext db = new TODOContext())
     {
         db.Todos.Add(item);
         db.SaveChanges();
     }
 }
コード例 #4
0
 public void Update(TODOItem todo)
 {
     using (TODOContext db = new TODOContext())
     {
         db.Todos.Attach(todo);
         db.Entry(todo).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
     }
 }
コード例 #5
0
        public ActionResult Create(TODOItem todo)
        {
            if (!ModelState.IsValid)
            {
                return(View(todo));
            }

            _dbManager.Insert(todo);

            TempData["Message"] = "Task created!";
            return(RedirectToAction("GetAllTasks"));
        }
コード例 #6
0
        public ActionResult Edit(TODOItem todo)
        {
            if (!ModelState.IsValid)
            {
                return(View(todo));
            }

            // Update database
            _dbManager.Update(todo);

            return(RedirectToAction("GetAllTasks"));
        }
コード例 #7
0
        public ActionResult DeleteConfirmed(int id)
        {
            TODOItem tODOItem = db.TODOItems.Find(id);

            db.TODOItems.Remove(tODOItem);
            if (DateTime.Now < tODOItem.EndDate)
            {
                var user = db.Users.Find(User.Identity.GetUserId());
                user.TodosDoneInTime++;
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #8
0
 public ActionResult Edit([Bind(Include = "Id,Title,Description,StartDate,EndDate,UserId")] TODOItem tODOItem)
 {
     if (ModelState.IsValid)
     {
         if (tODOItem.EndDate < tODOItem.StartDate)
         {
             ModelState.AddModelError(string.Empty, "End date can't be before start date.");
             return(View(tODOItem));
         }
         db.Entry(tODOItem).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tODOItem));
 }
コード例 #9
0
        // creates a list of TODO items and returns it
        // first updates all active sows in the database
        // TODO add a loading icon while the sows are updating and TODO list is being created
        public List <TODOItem> GetTODOList()
        {
            // create TODO list
            List <TODOItem> todos = new List <TODOItem>();

            // update all sows
            using (SQLiteConnection conn = new SQLiteConnection(App.FilePath))
            {
                // select all the sows from the database and add them to the list view
                conn.CreateTable <Sow>();
                var sows = conn.Query <Sow>("select * from Sow where Alive = ?", true).ToList();
                foreach (Sow sow in sows)
                {
                    // move sows to new status if time elapsed
                    sow.Update();
                    TODOItem todo;

                    // if sow status = READY_TO_BREED, add a Breed button to the listview item
                    // if sow status = PENDING_ULTRA_SOUND, add a Ultrasound button to the listview item
                    // if sow status = DUE, add a Farrow button to the list view
                    // if any other status, don't add a button to the listview item
                    if (sow.Status == "READY_TO_BREED")
                    {
                        todo = new TODOItem(sow.ID, sow.SowNo, sow.Status, "Breed", true, "#3483EB");
                        todos.Add(todo);
                    }
                    else if (sow.Status == "PENDING_ULTRASOUND")
                    {
                        todo = new TODOItem(sow.ID, sow.SowNo, sow.Status, "Ultrasound", true, "#F65C78");
                        todos.Add(todo);
                    }
                    else if (sow.Status == "DUE")
                    {
                        todo = new TODOItem(sow.ID, sow.SowNo, sow.Status, "Farrow", true, "#A0C334");
                        todos.Add(todo);
                    }
                    else
                    {
                        todo = new TODOItem(sow.ID, sow.SowNo, sow.Status, "Text", false, "#000000");
                        todos.Add(todo);
                    }
                }
            }

            return(todos);
        }
コード例 #10
0
 public ActionResult Edit(FormCollection collection)
 {
     try
     {
         using (TODOITEMEntity tODOITEMEntity = new TODOITEMEntity())
         {
             //let's grab checked items
             //loop thru items that were checked.
             // pass them to model to update status.
             string[] idArray    = new string[] { };
             string[] checkArray = new string[] { };
             foreach (var key in collection.AllKeys)
             {
                 if (key.ToLower().Contains("id"))
                 {
                     idArray = collection[key].Split(',');
                 }
                 if (key.Contains("itemChk"))
                 {
                     //first replace "true,false" with only true as form submit
                     //true followed by false for check box
                     checkArray = collection[key].Replace("true,false", "true").Split(',');
                 }
             }
             int checkArrayLenght = checkArray.Length;
             //run a loop on check array
             for (int i = 0; i < checkArrayLenght; i++)
             {
                 int ID = Convert.ToInt32(idArray[i]);
                 //check if check box was selected
                 if (checkArray[i].ToLower() == "true")
                 {
                     TODOItem itemToBeUpdated = tODOITEMEntity.TODOItems.SingleOrDefault(item => item.Id == ID);
                     itemToBeUpdated.Status = "Completed";
                 }
             }
             tODOITEMEntity.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         return(RedirectToAction("Error"));
     }
 }
コード例 #11
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TODOItem tODOItem = db.TODOItems.Find(id);

            if (tODOItem == null)
            {
                return(HttpNotFound());
            }
            if (tODOItem.UserId != User.Identity.GetUserId())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            return(View(tODOItem));
        }
コード例 #12
0
        public ActionResult Edit(FormCollection formCollection)
        {
            try
            {
                MyDBEntities myDBEntity = new MyDBEntities();

                string[] idArray     = new string[] { };
                string[] statusArray = new string[] { };

                foreach (string key in formCollection.AllKeys)
                {
                    //retrieve id and status values from form array
                    if (key.Contains("itemChk"))
                    {
                        statusArray = formCollection[key].Replace("true,false", "true").Split(',');
                    }
                    else if (key.Contains("Id"))
                    {
                        idArray = formCollection[key].Split(',');
                    }
                }
                //iterate thru status array as it will always have highest values.
                int lentgh = statusArray.Length;
                if (lentgh > 0)
                {
                    for (int i = 0; i < statusArray.Length; i++)
                    {
                        int ID = Convert.ToInt32(idArray[i]);
                        if (statusArray[i].ToLower() == "true")
                        {
                            TODOItem tODOItem = myDBEntity.TODOItems.SingleOrDefault(item => item.Id == ID);
                            tODOItem.Status = "Completed";
                        }
                    }
                }
                myDBEntity.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View("Error"));
            }
        }
コード例 #13
0
        public ActionResult Create([Bind(Include = "Id,Title,Description,StartDate,EndDate")] TODOItem tODOItem)
        {
            if (ModelState.IsValid)
            {
                if (tODOItem.EndDate < tODOItem.StartDate)
                {
                    ModelState.AddModelError(string.Empty, "End date can't be before start date.");
                    return(View(tODOItem));
                }
                var userId = User.Identity.GetUserId();
                tODOItem.UserId = userId;
                db.TODOItems.Add(tODOItem);
                var user = db.Users.Find(userId);
                user.TodosTotal++;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tODOItem));
        }
コード例 #14
0
 public ActionResult Delete(int id)
 {
     try
     {
         using (MyDBEntities myDBEntity = new MyDBEntities())
         {
             //get item from list by id
             TODOItem tODOItem = myDBEntity.TODOItems.FirstOrDefault(tdi => tdi.Id == id);
             if (tODOItem != null)
             {
                 myDBEntity.TODOItems.Remove(tODOItem);
                 myDBEntity.SaveChanges();
             }
         };
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View("Index"));
     }
 }
コード例 #15
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         //create an object of ToDoItem
         TODOItem toDoItem = new TODOItem()
         {
             Description = collection["Description"],
             Status      = collection["Status"]
         };
         //add new item to list;
         using (MyDBEntities myDBEntity = new MyDBEntities())
         {
             myDBEntity.TODOItems.Add(toDoItem);
             myDBEntity.SaveChanges();
             return(RedirectToAction("Index"));
         }
     }
     catch
     {
         return(View());
     }
 }
コード例 #16
0
 public Task DeleteTaskAsync(TODOItem item)
 {
     return(restService.DeleteTodoItemAsync(item.ID));
 }
コード例 #17
0
 public Task SaveTaskAsync(TODOItem item, bool isNewItem = false)
 {
     return(restService.SaveTodoItemAsync(item, isNewItem));
 }