public ActionResult Index(string searchTerm = null, string dropDownList = null)
        {
            var cDescription = string.Empty;
            var result = new proj_infoViewModel();
            var resultStatus = new proj_info();
            try
            {
                switch (dropDownList)
                {
                    case "1":
                        goto default;
                    case "2":
                        cDescription = "StakeHolder";
                        return RedirectToAction("searchStakeholder", new { searchTerm = searchTerm } );
            //                        break;
                    case "3":
                        cDescription = "Status";
                        return RedirectToAction("searchStatus", new { searchTerm = searchTerm });
            //                        break;
                    case "4":
                        cDescription = "Department";
                        return RedirectToAction("searchDepartment", new { searchTerm = searchTerm });
                        //break;
                    default:
                        cDescription = "Project Name";
                        result =
                                (from pi in _ctx.proj_info
                                                    .Include("proj_mgr.proj_sponsor.proj_type.proj_status.dept")
                                 select new proj_infoViewModel
                                 {
                                     _proj_info_id      =   pi.proj_info_id,
                                     _proj_name         =   pi.proj_name,
                                     _proj_mgr_id       =   pi.proj_mgr_id,
                                     _proj_sponsor_id   =   pi.proj_sponsor_id,
                                     _proj_goal         =   pi.proj_goal,
                                     _charter           =   pi.charter.Value,
                                     _scope_definition  =   pi.scope_definition,
                                     proj_type_id       =   pi.project_type_id,
                                     _proj_status_id    =   pi.proj_status_id,
                                     _dept_id           =   pi.dept_id.Value,
                                     _client            =   pi.client,
                                     _proj_start_date   =   pi.proj_start_date,
                                     _proj_end_date     =   pi.proj_end_date,
                                     _notes             =   pi.notes,
                                     _doc_location      =   pi.doc_location,
                                     _createdby         =   pi.createdby,
                                     _createddate       =   pi.createddate
                                 }).FirstOrDefault(r => searchTerm == null || r._proj_name.StartsWith(searchTerm));
                        break;
                }
            }
            catch
            {
                DisplayMessage(searchTerm, cDescription);
            }

            return View(result);
        }
        //        [HttpPost]
        public ActionResult UpdateProject(proj_infoViewModel info, int id)
        {
            // this is how you access the list of errors that can occur during the model binding.
            if (!ModelState.IsValid)
                return View(info);

            var p = projectInfo.GetProjectInfo(id);
            if (p == null)
                return RedirectToAction("Index");

            string projDesc = info._proj_name;
            var  pi = new proj_info
            {
                proj_info_id        =   id,
                proj_name           =   info._proj_name,
                proj_mgr_id         =   info._proj_mgr_id,
                proj_sponsor_id     =   info._proj_sponsor_id,
                charter             =   info._charter,
                scope_definition    =   info._scope_definition,
                dept_id             =   info._dept_id,
                client              =   info._client,
                proj_start_date     =   info._proj_start_date.Value,
                proj_end_date       =   info._proj_end_date,
                proj_status_id      =   info._proj_status_id,
                project_type_id     =   info.proj_type_id,
                createdby           =   User.Identity.Name.Replace("GREENSPOONMARDE\\", ""),
                createddate         =   DateTime.Now,
                notes               =   info._notes,
                proj_goal           =   info._proj_goal,
                doc_location        =   info._doc_location
            };

            var existingProjInfo = _ctx.proj_info.Find(pi.proj_info_id);
            if (existingProjInfo != null)
            {
                // entity already in the context
                var attachedEntry = _ctx.Entry(existingProjInfo);
                attachedEntry.CurrentValues.SetValues(pi);
            }
            _ctx.SaveChanges();
            TempData["ConfirmationMessage"] = pi.proj_name + " has been updated.";
            // I want to redirect here instead of just letting the users sit on the save values on that posted form fields, it is very common after HTTP POST you redirect them back to a page where they
            // can view the changed results, THAT WAY, they don't hit refresh on the result of this post operation and accidentally submit something twice.
            return RedirectToAction("Index", new { searchTerm = projDesc });
        }
        public ActionResult CreateProject(proj_infoViewModel info)
        {
            string projDesc = info._proj_name;

            if (ModelState.IsValid)
            {
                var p = new proj_info
                {
                    proj_name           = info._proj_name,
                    proj_mgr_id         = info._proj_mgr_id,
                    proj_sponsor_id     = info._proj_sponsor_id,
                    charter             = info._charter,
                    scope_definition    = info._scope_definition,
                    dept_id             = info._dept_id,
                    client              = info._client,
                    proj_start_date     = info._proj_start_date.Value,
                    proj_end_date       = info._proj_end_date,
                    proj_status_id      = info._proj_status_id,
                    project_type_id     = info.proj_type_id,
                    createdby           = info._createdby,
                    createddate         = info._createddate.Value,
                    notes               = info._notes,
                    proj_goal           = info._proj_goal,
                    doc_location        = info._doc_location
                };
                    _ctx.proj_info.Add(p);
                    _ctx.SaveChanges();
                    return RedirectToAction("Index", new { searchTerm = projDesc });

            }

            return View(info);
        }
Exemple #4
0
        // Update
        //originalEntity represents the object before the change (usually fetched from database before you update).
        //It must be attached to the context. changedEntity represents the entity with the same key which has been changed.
        public static void UpdateProject(proj_info proj_info, Func<proj_info, int> getKey)
        {
            //            _ctx.Entry(proj_info).CurrentValues.SetValues(proj_info);
            if (proj_info == null)
            {
                throw new ArgumentException("Cannot add a null entry");
            }

            // To get information about an entity in question, and it's relation to the current DbContext, you call a DbContext.Entry method
            var entry = _ctx.Entry(proj_info);

            //            Debug.Write(entry.State);  //EntityState.Detached

            if (entry.State == EntityState.Detached)
            {
                var set = _ctx.Set<proj_info>();
                proj_info attachedEntity = set.Find(getKey(proj_info));

                if (attachedEntity != null)
                {
                    var attachedEntry = _ctx.Entry(attachedEntity);
                    attachedEntry.CurrentValues.SetValues(proj_info);
                }
                else
                {
                    entry.State = EntityState.Modified; // this should attached the entry
                }
            }
        }
Exemple #5
0
 // Delete
 public static void DeleteProject(proj_info proj_info)
 {
     _ctx.proj_info.Remove(proj_info);
 }
Exemple #6
0
 // Methods to add, update, delete, and save individual Project
 public static void AddProject(proj_info proj_info)
 {
     _ctx.proj_info.Add(proj_info);
 }
Exemple #7
0
 public static void UpdateProject(proj_info proj_info)
 {
     using (var db = new PMEntities())
     {
         var existingProjInfo = db.proj_info.Find(proj_info.proj_info_id);
         if (existingProjInfo != null)
         {
             // entity already in the context
             var attachedEntry = db.Entry(existingProjInfo);
             attachedEntry.CurrentValues.SetValues(proj_info);
         }
         else
         {
             // Since we don't have it in db, this is a simple add.
             db.proj_info.Add(proj_info);
         }
     }
 }