public ActionResult Edit(int id, CaseEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.CaseId != id)
            {
                ModelState.AddModelError("", "Not a valid Case Id.");
                return(View(model));
            }

            var service = CreateCaseService();

            if (service.UpdateCase(model, id))

            {
                TempData["SaveResult"] = "Case has been added to our database.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Case could not be added, please confirm all necessary information has been entered.");

            return(View(model));
        }
Example #2
0
        // GET : Case/Edit/{id}
        public ActionResult Edit(int id)
        {
            var service = new CaseService();
            var detail  = service.GetCaseById(id);
            var model   = new CaseEdit
            {
                Name                     = detail.Name,
                Manufacturer             = detail.Manufacturer,
                Color                    = detail.Color,
                PowerSupply              = detail.PowerSupply,
                Type                     = detail.Type,
                SidePanelWindow          = detail.SidePanelWindow,
                PowerSupplyShroud        = detail.PowerSupplyShroud,
                FrontPanelUSB            = detail.FrontPanelUSB,
                MotherboardFormFactor    = detail.MotherboardFormFactor,
                External52Bay            = detail.External52Bay,
                External35Bay            = detail.External35Bay,
                Internal35Bay            = detail.Internal35Bay,
                Internal25Bay            = detail.Internal25Bay,
                FullHeightExpansionSlots = detail.FullHeightExpansionSlots,
                HalfHeightExpansionSlots = detail.HalfHeightExpansionSlots,
                IsAvailable              = detail.IsAvailable
            };

            return(View(model));
        }
        public bool UpdateCase(CaseEdit model)
        {
            using (var _db = new ApplicationDbContext())
            {
                var caseEntity =
                    _db
                    .Cases
                    .SingleOrDefault(e => e.CaseId == model.CaseId);
                caseEntity.Name                     = model.Name;
                caseEntity.Manufacturer             = model.Manufacturer;
                caseEntity.Color                    = model.Color;
                caseEntity.PowerSupply              = model.PowerSupply;
                caseEntity.Type                     = model.Type;
                caseEntity.SidePanelWindow          = model.SidePanelWindow;
                caseEntity.PowerSupplyShroud        = model.PowerSupplyShroud;
                caseEntity.FrontPanelUSB            = model.FrontPanelUSB;
                caseEntity.MotherboardFormFactor    = model.MotherboardFormFactor;
                caseEntity.External52Bay            = model.External52Bay;
                caseEntity.External35Bay            = model.External35Bay;
                caseEntity.Internal35Bay            = model.Internal35Bay;
                caseEntity.Internal25Bay            = model.Internal25Bay;
                caseEntity.FullHeightExpansionSlots = model.FullHeightExpansionSlots;
                caseEntity.HalfHeightExpansionSlots = model.HalfHeightExpansionSlots;
                caseEntity.IsAvailable              = model.IsAvailable;

                return(_db.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int id)
        {
            var service = CreateCaseService();
            var detail  = service.GetCaseById(id);
            var model   =
                new CaseEdit
            {
                CaseId  = detail.CaseId,
                Summary = detail.Summary,
            };

            return(View(model));
        }
Example #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            CaseEdit.RaceEthnicityList.AddRange(RaceEthnicityList.Where(item => item.IsChecked).Select(item => item.Id).ToList());
            CaseEdit.VulnerabilityList.AddRange(VulnerabilityList.Where(item => item.IsChecked).Select(item => item.Id).ToList());
            CaseEdit.CaseLawEnforcementList.AddRange(CaseLawEnforcementItemList.Where(item => item.AgencyId > 0).Select(item => new NameValueListBase <int, bool> .NameValuePair(item.AgencyId, item.Denial)));

            CaseEdit = await CaseEdit.SaveAsync(true);

            return(RedirectToPage("./Index"));
        }
Example #6
0
 public bool UpdateCase(CaseEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity =
             ctx
             .Cases
             .Single(e => e.CaseKeyId == model.CaseKeyId && e.OwnerId == _userId);
         entity.DateOfIncident = model.DateOfIncident;
         entity.BadgeId        = model.BadgeId;
         entity.SuspectId      = model.SuspectId;
         entity.CrimeId        = model.CrimeId;
         return(ctx.SaveChanges() == 1);
     }
 }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CaseEdit = await DataPortal.FetchAsync <CaseEdit>(id);

            if (CaseEdit == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Example #8
0
        public IHttpActionResult PutCase(CaseEdit currentCase)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateCaseService();

            if (!service.UpdateCase(currentCase))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Example #9
0
        public bool UpdateCase(CaseEdit model, int id)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .Cases
                    .Single(e => e.CaseId == id && e.UserId == _userId);

                entity.Summary      = model.Summary;
                entity.Title        = model.Title;
                entity.CaseYear     = model.CaseYear;
                entity.HouseControl = model.SenateControl;
                entity.ModifiedUTC  = DateTimeOffset.UtcNow;

                return(ctx.SaveChanges() == 1);
            }
        }
Example #10
0
        public ActionResult Edit(int id, CaseEdit model)
        {
            if (model.CaseId != id)
            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = new CaseService();

            if (service.UpdateCase(model))
            {
                TempData["SaveResult"] = "Your Case information was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your Case information could not be updated.");
            return(View());
        }
Example #11
0
 public CaseEditView()
 {
     InitializeComponent();
     _edit = new CaseEdit(grid, grid.View as TableView);
 }