Update() private method

private Update ( ) : void
return void
Esempio n. 1
0
        public async Task <IActionResult> Delete(int cid, int pid, bool post = true)
        {
            var prob = Problems.SingleOrDefault(p => p.ProblemId == pid);

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

            await Store.DeleteAsync(prob);

            await HttpContext.AuditAsync("detached", $"{pid}");

            await Notifier.Delete(cid, prob);

            var newprobs = await Store.ListAsync(cid);

            foreach (var @new in newprobs)
            {
                if (@new.Rank >= prob.Rank)
                {
                    await Notifier.Update(cid, @new);
                }
            }

            StatusMessage = $"Contest problem {prob.ShortName} has been deleted.";
            return(RedirectToAction("Home", "Jury"));
        }
Esempio n. 2
0
        //-------------------------------------------------------------------------------------------------------------------------------
        //                                  Event for "Update" button
        //-------------------------------------------------------------------------------------------------------------------------------
        private void onUpdateButtonClick(object sender, EventArgs e)
        {
            Notifier.Type noteType = Notifier.Type.INFO;

            if (radioButtonInfo.Checked)
            {
                noteType = Notifier.Type.INFO;
            }

            if (radioButtonOk.Checked)
            {
                noteType = Notifier.Type.OK;
            }

            if (radioButtonWarning.Checked)
            {
                noteType = Notifier.Type.WARNING;
            }

            if (radioButtonError.Checked)
            {
                noteType = Notifier.Type.ERROR;
            }

            Notifier.Update((short)numericNote.Value,                       // Update the note
                            textNote.Text,
                            noteType,
                            textTitle.Text);
        }
Esempio n. 3
0
        protected virtual async Task OnValidAsync(EditContext editContext)
        {
            Processing = true;
            await InvokeAsync(() => StateHasChanged());
            await CloseEditDialog();

            try
            {
                if (Mode == EditMode.CreateNew)
                {
                    try
                    {
                        EdittingModel.CreateNew(DB.Context, Config);
                    }
                    catch (Exception e)
                    {
                        ErrorSubject = e.Message;
                        ErrorMessage = e.StackTrace;
                    }
                    DB.Context.SaveChanges();
                    OnAfterCreateAndCloseDialog(EdittingModel);
                    await OnAfterCreateAsync(EdittingModel);
                }
                if (Mode == EditMode.Edit)
                {
                    var previous = EdittingModel.GetEntityAsNoTracking(DB.Context, Config);
                    try
                    {
                        EdittingModel.Update(DB.Context, Config, previous);
                    }
                    catch (Exception e)
                    {
                        ErrorSubject = e.Message;
                        ErrorMessage = e.StackTrace;
                    }
                    DB.Context.SaveChanges();
                    OnAfterUpdateAndCloseDialog(EdittingModel);
                    await OnAfterUpdateAsync(EdittingModel);
                }
                await InvokeAsync(() => StateHasChanged());
                await InvokeAsync(() => Notifier.Update());

                Processing = false;
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
                Processing   = false;
                Console.Error.WriteLine(e);
                await CloseEditDialog();

                return;
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Add(int cid, ContestProblem model)
        {
            if (Problems.Any(cp => cp.ShortName == model.ShortName))
            {
                ModelState.AddModelError("xys::duplicate", "Duplicate short name for problem.");
            }
            var probDetect = await Store.CheckAvailabilityAsync(cid, model.ProblemId, User);

            if (!probDetect.ok)
            {
                ModelState.AddModelError("xys::prob", probDetect.msg);
            }

            if (ModelState.IsValid)
            {
                var oldprobs = Problems;
                model.Color     = "#" + model.Color.TrimStart('#');
                model.ContestId = cid;
                await Store.CreateAsync(model);

                await HttpContext.AuditAsync("attached", $"{model.ProblemId}");

                var newprobs = await Store.ListAsync(cid);

                var nowp = newprobs.SingleOrDefault(p => p.ProblemId == model.ProblemId);
                await Notifier.Create(cid, nowp);

                foreach (var @new in newprobs)
                {
                    if (@new.Rank > nowp.Rank)
                    {
                        await Notifier.Update(cid, @new);
                    }
                }

                StatusMessage = $"Problem {model.ShortName} saved.";
                return(RedirectToAction("Home", "Jury"));
            }
            else
            {
                return(Window(model));
            }
        }
Esempio n. 5
0
        protected async Task RemoveAsync(T model)
        {
            if (!Permision.HasFlag(EntityManagementPermision.CanRemove))
            {
                ErrorSubject = "Permission Error";
                ErrorMessage = "You can not remove entity.";
                return;
            }
            if (model == null)
            {
                return;
            }
            if (!await JS.InvokeAsync <bool>("confirmDialog", new[] { "Are you sure?" }))
            {
                return;
            }
            var m = model.GetEntityForEditOrRemove(DB.Context, Config);

            if (m == null)
            {
                ErrorSubject = "Error";
                ErrorMessage = "Not found the entity";
                return;
            }
            try
            {
                m.Remove(DB.Context, Config);
            }
            catch (Exception e)
            {
                ErrorSubject = e.Message;
                ErrorMessage = e.StackTrace;
            }
            DB.Context.SaveChanges();

            await OnAfterRemoveAsync();
            await InvokeAsync(() => StateHasChanged());
            await InvokeAsync(() => Notifier.Update());
        }
Esempio n. 6
0
        public async Task <IActionResult> Edit(int cid, int pid, ContestProblem model)
        {
            if (!Problems.Any(cp => cp.ProblemId == pid))
            {
                return(NotFound());
            }
            if (Problems.Any(cp => cp.ShortName == model.ShortName && cp.ProblemId != pid))
            {
                ModelState.AddModelError("xys::duplicate", "Duplicate short name for problem.");
            }
            if (!ModelState.IsValid)
            {
                return(Window(model));
            }

            await Store.UpdateAsync(cid, pid,
                                    () => new ContestProblem
            {
                Color       = "#" + model.Color.TrimStart('#'),
                AllowSubmit = model.AllowSubmit,
                ShortName   = model.ShortName,
                Score       = model.Score,
            });

            await HttpContext.AuditAsync("updated", $"{pid}");

            var newprobs = await Store.ListAsync(cid);

            foreach (var @new in newprobs)
            {
                await Notifier.Update(cid, @new);
            }

            StatusMessage = $"Problem {model.ShortName} saved.";
            return(RedirectToAction("Home", "Jury"));
        }
Esempio n. 7
0
 private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
 {
     Notifier.Update(GetType().GetProperty("WallPaperPath"));
 }