Esempio n. 1
0
        public ActionResult EditPrisoner(Prisoners prisoner)
        {
            var id = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                var history = new ChangesHistory()
                {
                    Worker_Id = id,
                    Date      = DateTime.Now.Date
                };
                _db.Entry(prisoner).State = EntityState.Modified;

                var prisonerChangesHistory = new PrisonerChangesHistory()
                {
                    PrisonerName    = prisoner.PrisonerName,
                    PrisonerSurname = prisoner.PrisonerSurname,
                    Pesel           = prisoner.Pesel,
                    FK_PrisonerChangesHistory_Prisoner_Id = prisoner.Prisoner_Id,
                    Sex = prisoner.Sex,
                    FK_PrisonerChangesHistory_ChangesHistory_Id = history.Record_Id
                };

                _db.ChangesHistory.Add(history);
                _db.PrisonerChangesHistory.Add(prisonerChangesHistory);
                _db.SaveChanges();
                return(RedirectToAction("GetPrisoners", "Prisoners"));
            }
            return(View(prisoner));
        }
Esempio n. 2
0
        public ActionResult EditJudgement(EditJudgementViewModel model)
        {
            var list = _db.CategoriesOfCrimes.ToList();

            ViewBag.KatList = new SelectList(list, "CategoryOfCrime_Id", "NameOfCategory");
            var id = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                var history = new ChangesHistory
                {
                    Worker_Id = id,
                    Date      = DateTime.Now.Date
                };
                _db.Entry(model.Judgement).State = EntityState.Modified;

                var judgementChangesHistory = new JudgementsChangesHistory
                {
                    Prisoner_id = model.Prisoner_Id,
                    Time        = model.Judgement.TimeOfJudgement,
                    Date        = model.Judgement.StartDate,
                    FK_JudgementsChangesHistory_ChangesHistory_Id = history.Record_Id,
                    FK_JudgementsChangesHistory_Judgements        = model.Judgement.Judgement_Id,
                    CategoryOfCrimes_Id = model.Judgement.FK_Judgements_CategoriesOfCrimes_Id
                };

                _db.ChangesHistory.Add(history);
                _db.JudgementsChangesHistory.Add(judgementChangesHistory);
                _db.SaveChanges();
                var idTemp = judgementChangesHistory.Prisoner_id;
                return(RedirectToAction("ReallocatePrisoner", new { id = idTemp }));
            }
            return(View(model));
        }
Esempio n. 3
0
        public ActionResult ReallocatePrisoner(AllocationViewModel model)
        {
            var id = System.Web.HttpContext.Current.User.Identity.GetUserId();


            var cell = _db.Cells.FirstOrDefault(x => x.Cell_Id == model.Cell_Id);

            if (cell == null)
            {
                return(HttpNotFound());
            }
            var count = _db.Allocation.Count(x => x.FK_Allocation_Cells_Id == cell.Cell_Id);

            if (cell.IsEmpty && count < cell.Size)
            {
                var allocation = _db.Allocation.FirstOrDefault(s => s.FK_Allocation_Prisoners_Id == model.Prisoner_Id);

                if (allocation != null)
                {
                    allocation.FK_Allocation_Cells_Id = cell.Cell_Id;
                    _db.Entry(allocation).State       = EntityState.Modified;
                }
                var history = new ChangesHistory()
                {
                    Worker_Id = id,
                    Date      = DateTime.Now.Date
                };

                var allocationHistory = new AllocationChangesHistory()
                {
                    Cell_Id = cell.Cell_Id,
                    FK_AllocationChangesHistory_ChangesHistory_Id = history.Record_Id,
                    FK_AllocationChangesHistory_Allocation_Id     = allocation.FK_Allocation_Prisoners_Id
                };
                if (count + 1 == cell.Size)
                {
                    cell.IsEmpty          = false;
                    _db.Entry(cell).State = EntityState.Modified;
                }
                if (count - 1 < cell.Size)
                {
                    cell.IsEmpty          = true;
                    _db.Entry(cell).State = EntityState.Modified;
                }


                _db.ChangesHistory.Add(history);
                _db.AllocationChangesHistory.Add(allocationHistory);
                _db.SaveChanges();
                return(RedirectToAction("GetPrisoners", "Prisoners"));
            }
            return(View(model));
        }
Esempio n. 4
0
        public static SyncStatus GetSyncStatus(SqlBase source_con, Guid guid, SyncStatus SyncStatus)
        {
            var history = source_con.Table <SyncHistory>().FirstOrDefault(x => x.Guid == guid);

            if (history is null)
            {
                ChangesHistory changes = source_con.Table <ChangesHistory>().FirstOrDefault(x => x.Guid == guid);
                if (changes is null)
                {
                    //Has been downloaded by Daemon service since daemon downloads dont get inserted here
                    SyncStatus = SyncStatus.Done;
                    return(SyncStatus);
                }
                if (SyncStatus == SyncStatus.Failed)
                {
                    return(SyncStatus.Failed);
                }
                SyncStatus = SyncStatus.Pending;
                return(SyncStatus.Pending);
            }
            SyncStatus = SyncStatus.Done;
            return(SyncStatus.Done);
        }
Esempio n. 5
0
        public async Task <IActionResult> OnGetAsync(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MtdStore = await _context.MtdStore.FirstOrDefaultAsync(m => m.Id == id);

            if (MtdStore == null)
            {
                return(NotFound());
            }

            var user = await _userHandler.GetUserAsync(HttpContext.User);

            bool isViewer = await _userHandler.IsViewer(user, MtdStore.MtdForm, MtdStore.Id);

            IsEditor = await _userHandler.IsEditor(user, MtdStore.MtdForm, MtdStore.Id);

            IsInstallerOwner = await _userHandler.IsInstallerOwner(user, MtdStore.MtdForm, MtdStore.Id);

            if (!isViewer)
            {
                return(Forbid());
            }


            MtdForm = await _context.MtdForm.Include(m => m.InverseParentNavigation).FirstOrDefaultAsync(x => x.Id == MtdStore.MtdForm);

            MtdLogDocument edited = await _context.MtdLogDocument.Where(x => x.MtdStore == MtdStore.Id).OrderByDescending(x => x.TimeCh).FirstOrDefaultAsync();

            MtdLogDocument created = await _context.MtdLogDocument.Where(x => x.MtdStore == MtdStore.Id).OrderBy(x => x.TimeCh).FirstOrDefaultAsync();

            StoreOwner = await _context.MtdStoreOwner.Where(x => x.Id == MtdStore.Id).FirstOrDefaultAsync();

            ChangesHistory = new ChangesHistory
            {
                CreateByTime = MtdStore.Timecr.ToString()
            };

            if (edited != null)
            {
                ChangesHistory.LastEditedUser = edited.UserName;
                ChangesHistory.LastEditedTime = edited.TimeCh.ToString();
            }

            if (created != null)
            {
                if (MtdStore.Timecr.Date == created.TimeCh.Date)
                {
                    ChangesHistory.CreateByUser = created.UserName;
                }
            }

            List <WebAppUser> webAppUsers = await _userHandler.GetUsersInGroupsAsync(user);

            ViewData["UsersList"] = new SelectList(webAppUsers, "Id", "Title");

            ApprovalHandler approvalHandler = new ApprovalHandler(_context, MtdStore.Id);

            IsApprover = await approvalHandler.IsApproverAsync(user);

            IsFirstStage = await approvalHandler.IsFirstStageAsync();

            IList <MtdApprovalStage> stages = await approvalHandler.GetStagesDownAsync();

            ViewData["Stages"] = new SelectList(stages.OrderByDescending(x => x.Stage), "Id", "Name");

            List <string> partIds = await approvalHandler.GetWilBeBlockedPartsIds();

            BlockParts = new List <MtdFormPart>();
            if (partIds.Count > 0)
            {
                BlockParts = await _context.MtdFormPart.Where(x => partIds.Contains(x.Id)).OrderBy(x => x.Sequence).ToListAsync();
            }
            IsFormApproval = await approvalHandler.IsApprovalFormAsync();

            if (IsFormApproval)
            {
                ApprovalStatus = await approvalHandler.GetStatusAsync(user);
            }


            return(Page());
        }