예제 #1
0
 public int AddTopic(Topic topic)
 {
     DbContext.Topics.Add(topic);
     try
     {
         DbContext.SaveChanges();
         return topic.ID;
     }
     catch (Exception ex)
     {
         return -1;
     }
 }
예제 #2
0
        public ActionResult edit(Topic topic)
        {
            ViewBag.MainNav = Navigator.Main.TOPIC;

            if (ModelState.IsValid)
            {
                int new_id = topicService.UpdateTopic(topic);

                if (new_id > 0)
                {
                    TempData["SuccessMessage"] = "Topic Updated Successfully";
                    return RedirectToAction("Edit", new { id = new_id });
                }
                else
                    TempData["ErrorMessage"] = "Topic Failed To Update";
            }
            return View();
        }
예제 #3
0
        public int UpdateTopic(Topic topic)
        {
            Topic A = DbContext.Topics.Where(a => a.ID == topic.ID).FirstOrDefault();

            if (A == null)
                return -1;

            A.Name = topic.Name;
            A.NameAr = topic.NameAr;

            try
            {
                DbContext.SaveChanges();
                return A.ID;
            }
            catch (Exception ex)
            {
                return -1;
            }

        }