public ActionResult UpdateDelete(OwnershipViewModel OSPViewModel, string command)
        {
            string PageAction = "";
            bool   result     = false;

            user = (UserSession)Session["User"];

            if (command == "Save")
            {
                OwnershipManager OSPManager = new OwnershipManager();
                result     = OSPManager.UpdateOwnership(OSPViewModel);
                PageAction = "UPDATE";
            }
            else if (command == "Delete")
            {
                OwnershipManager OSPManager = new OwnershipManager();
                result     = OSPManager.DeleteOwnership(OSPViewModel);
                PageAction = "DELETE";
            }
            if (result)
            {
                TempData["SuccessMessage"] = PageAction + " successful";
                new AuditLogManager().Audit(user.Username, DateTime.Now, "Ownership", PageAction, OSPViewModel.Id, OSPViewModel.OWNSHP);
            }
            else
            {
                TempData["ErrorMessage"] = PageAction + " failed";
            }
            return(RedirectToAction("Index"));
        }
        // GET: Ownership
        public ActionResult Index()
        {
            // Validate log in and user access
            UserAccessSession UASession = (UserAccessSession)Session["UserAccess"];

            // OWN -> Ownership
            // Refer to UserAccessSession
            if (UASession == null || !UASession.OWN)
            {
                return(RedirectToAction("Login", "Account"));
            }

            user = (UserSession)Session["User"];
            Session["CurrentPage"] = new CurrentPageSession("OWN", "HOME", "LOG");

            // Get all data stored in DB table
            OwnershipManager   OSPManager   = new OwnershipManager();
            OwnershipViewModel OSPViewModel = new OwnershipViewModel();

            OSPViewModel.OHPList = OSPManager.GetOSP();
            if (OSPViewModel.OHPList == null || OSPViewModel.OHPList.Count() == 0)
            {
                OSPViewModel.OHPList = new List <OwnershipViewModel>();
            }
            // return View with ViewModel
            return(View(OSPViewModel));
        }
Example #3
0
        public ActionResult UpdateOwnership(OwnershipViewModel owner)
        {
            var nOwner = new Ownership();

            nOwner = Mapper.Map <Ownership>(owner);
            this.OwnershipService.UpdateOwnership(nOwner);
            return(View());
        }
Example #4
0
        public ActionResult CreateUpdateOwnership(OwnershipViewModel owner)
        {
            var nowner = Mapper.Map <Ownership>(owner);

            try
            {
                var result = false;
                if (nowner.Id == 0)
                {
                    var entity = this.OwnershipService.CreateOwnership(nowner);
                    result = entity.Id != 0;

                    if (Request.Files.Count > 0)
                    {
                        var file = Request.Files[0];

                        if (file != null && file.ContentLength > 0)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var path     = Path.Combine(Server.MapPath("~/Images/"), fileName);
                            file.SaveAs(path);
                            this.MultimediaService.CreateMultimedia(new Multimedia()
                            {
                                MultimediaTypeId = (int)TipoMultimedia.Foto,
                                Url         = fileName,
                                OwnershipId = entity.Id
                            });
                        }
                    }
                }
                else
                {
                    result = this.OwnershipService.UpdateOwnership(nowner);
                }
                if (result)
                {
                    return(View("CreateSuccess"));
                }
                else
                {
                    return(View("../Shared/Error"));
                }
            }
            catch (Exception ex)
            {
                return(View("../Shared/Error"));
            }
        }
Example #5
0
 public List <OwnershipViewModel> GetOSP()
 {
     using (CFMMCDEntities db = new CFMMCDEntities())
     {
         List <OwnershipViewModel> OSPList = new List <OwnershipViewModel>();
         foreach (OWNERSHIP osp in db.OWNERSHIPs)
         {
             OwnershipViewModel OSPViewModel = new OwnershipViewModel();
             OSPViewModel.Id     = (osp.Id).ToString();
             OSPViewModel.OWNSHP = osp.OWNSHP;
             // Add to List
             OSPList.Add(OSPViewModel);
         }
         return(OSPList);
     }
 }
Example #6
0
        public bool UpdateOwnership(OwnershipViewModel OSPViewModel)
        {
            using (CFMMCDEntities db = new CFMMCDEntities())
            {
                OWNERSHIP ospRow = new OWNERSHIP();

                ospRow.Id     = int.Parse(OSPViewModel.Id);
                ospRow.OWNSHP = OSPViewModel.OWNSHP;
                try
                {
                    if (db.OWNERSHIPs.Where(o => o.Id.ToString().Equals(OSPViewModel.Id)).Any())
                    {
                        var rowToRemove = db.OWNERSHIPs.Single(o => o.Id.ToString().Equals(OSPViewModel.Id));
                        db.OWNERSHIPs.Remove(rowToRemove);
                        db.OWNERSHIPs.Add(ospRow);
                    }
                    else
                    {
                        db.OWNERSHIPs.Add(ospRow);
                    }
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e.Source);
                    System.Diagnostics.Debug.WriteLine(e.Message);
                    System.Diagnostics.Debug.WriteLine(e.StackTrace);
                    System.Diagnostics.Debug.WriteLine(e.InnerException);
                    Exception f = e.InnerException;
                    while (f != null)
                    {
                        System.Diagnostics.Debug.WriteLine("INNER:");
                        System.Diagnostics.Debug.WriteLine(f.Message);
                        System.Diagnostics.Debug.WriteLine(f.Source);
                        f = f.InnerException;
                    }
                    System.Diagnostics.Debug.WriteLine(e.Data);
                    return(false);
                }
            }
        }