示例#1
0
        public bool UpdateProject(Project instance)
        {
            try
            {
                Project project = Db.Projects.Find(instance.ProjectId);
                Type type = instance.GetType();

                foreach (var info in type.GetProperties())
                {
                    if (info.CanWrite)
                    {
                        var value = info.GetValue(instance);
                        if (value != null)
                        {
                            info.SetValue(project, value, null);
                        }
                    }
                }
                Db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
示例#2
0
 public ActionResult Edit(Project project)
 {
     ViewBag.CategoryId = new SelectList(Repository.Categories, "CategoryId", "Name", project.CategoryId);
     if (ModelState.IsValid)
     {
         var result = Repository.UpdateProject(project);
     }
     return RedirectToAction("Edit", new { projectId = project.ProjectId });
 }
示例#3
0
        public ActionResult Create(Project project)
        {
            if (ModelState.IsValid)
            {
                db.Projects.Add(project);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", project.CategoryId);
            return View(project);
        }
示例#4
0
 public ActionResult Add()
 {
     var project = new  Project()
     {
         AuthorId = CurrentUser.UserId,
         EventDate = null,
         OrganizationDate = null,
         AddedTime = DateTime.Now,
         ChangeTime = DateTime.Now
     };
     var result = Repository.CreateProject(project);
     return RedirectToAction("Edit", new {projectId=project.ProjectId});
 }
示例#5
0
 public bool CreateProject(Project instance)
 {
     try
     {
         if (instance.ProjectId == 0)
         {
             Db.Projects.Add(instance);
             Db.SaveChanges();
             return true;
         }
         return false;
     }
     catch
     {
         return false;
     }
 }
示例#6
0
 public ActionResult Edit(Project project)
 {
     if (ModelState.IsValid)
     {
         db.Entry(project).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", project.CategoryId);
     return View(project);
 }