Beispiel #1
0
 public ActionResult Create(Register_SC register_SC)
 {
     try
     {
         var     chkIDCard = db.Register_SC.FirstOrDefault(x => x.REG_IDCard == register_SC.REG_IDCard);
         Applied applied   = new Applied()
         {
             APP_ReNO   = register_SC.REG_IDCard,
             APP_GenNO  = Convert.ToInt32(Session["IDSC"]),
             APP_Status = 3
         };
         Session.Remove("IDSC");
         db.Applieds.Add(applied);
         if (chkIDCard == null)
         {
             db.Register_SC.Add(register_SC);
         }
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     catch (Exception)
     {
         return(View(register_SC));
     }
 }
Beispiel #2
0
 protected void Applied(Applied <S, C> applied)
 {
     if (_applied == null)
     {
         _applied = applied;
     }
     else if (applied.state != null)
     {
         if (applied.metadata.IsEmpty)
         {
             _applied = _applied.AlongWith(applied.state, applied.Sources(), _applied.metadata);
         }
         else
         {
             _applied = _applied.AlongWith(applied.state, applied.Sources(), applied.metadata);
         }
     }
     else if (applied.state == null)
     {
         if (applied.metadata.IsEmpty)
         {
             _applied = _applied.AlongWith(applied.state, applied.Sources(), _applied.metadata);
         }
         else
         {
             _applied = _applied.AlongWith(applied.state, applied.Sources(), applied.metadata);
         }
     }
 }
Beispiel #3
0
        public void BlockVerify(Block block)
        {
            lock (Chain)
            {
                Chain.Add(block);
            }

            lock (TransactionPool)
            {
                var ids = block.Transactions.Select(x => x.Id).ToArray();
                TransactionPool.RemoveTxs(ids);
            }

            lock (Utxos)
            {
                var inEntries = block.Transactions.SelectMany(x => x.Inputs);
                Utxos.RemoveAll(x =>
                                inEntries.Any(inEntry =>
                                              inEntry.OutputIndex == x.OutIndex &&
                                              inEntry.TransactionId.Equals(x.TransactionId)));
                var utxos =
                    block.Transactions
                    .Select(x => (x.Outputs, x.Id))
                    .SelectMany(x => ToTxO(x.Outputs, x.Id));

                Utxos.AddRange(utxos);
            }

            //if(Chain.Count % 100 == 0) Difficulty.CalculateNextDifficulty()

            Applied?.Invoke();
        }
Beispiel #4
0
        void AppendToStream(IIdentity id, string envelopeId, Applied then, string explanation)
        {
            var stream = _factory.GetOrCreateStream(IdentityConvert.ToStream(id));
            var b      = new EnvelopeBuilder("unknown");

            b.AddString("caused-by", envelopeId);

            if (!String.IsNullOrEmpty(explanation))
            {
                b.AddString("explain", explanation);
            }
            foreach (var e in then.Events)
            {
                b.AddItem((object)e);
            }
            var data = _streamer.SaveEnvelopeData(b.Build());

            Context.Debug("?? Append {0} at v{3} to '{1}' in thread {2}", then.Events.Count,
                          IdentityConvert.ToStream(id),
                          Thread.CurrentThread.ManagedThreadId,
                          then.Version);

            if (!stream.TryAppend(data, TapeAppendCondition.VersionIs(then.Version)))
            {
                throw new InvalidOperationException("Failed to update the stream - it has been changed concurrently");
            }
        }
Beispiel #5
0
        private async Task ApplyInternal(bool reset = true)
        {
            try
            {
                using (MessageView.ShowLoad("Применение изменений..."))
                {
                    Repository.SaveScenario(_clonedScenario);
                    StatisticsManager.ReRegister(_clonedScenario);
                    await _clonedScenario.Initialize();

                    _clonedScenario.AfterInitilize();
                }

                IsModified = false;

                if (reset)
                {
                    if (await SetScenario(_clonedScenario))
                    {
                        Applied?.Invoke();
                    }
                }
                else
                {
                    _originalSenario = _clonedScenario; //crutch
                    Applied?.Invoke();
                }
            }
            catch (Exception e)
            {
                Log.Error($"Ошибка инициализации сценария [{_clonedScenario.Name}]", e);
            }
        }
Beispiel #6
0
        public void Apply(BehavioursComponent behaviours)
        {
            behaviours.Apply(Behaviour, behaviours.gameObject);
            IsApplied = true;

            Applied?.Invoke(this);
        }
        public Applied Load(ICollection <ICommand <IIdentity> > commands)
        {
            var id      = commands.First().Id;
            var stream  = _factory.GetOrCreateStream(IdentityConvert.ToStream(id));
            var records = stream.ReadRecords(0, int.MaxValue).ToList();
            var events  = records
                          .SelectMany(r => _streamer.ReadAsEnvelopeData(r.Data).Items.Select(m => (IEvent <IIdentity>)m.Content))
                          .ToArray();

            var then = new Applied();

            if (records.Count > 0)
            {
                then.Version = records.Last().Version;
            }

            var recipeId = id as RecipeId;

            if (recipeId != null)
            {
                var state = new RecipeAggregateState(events);
                var agg   = new RecipeAggregate(state, then.Events.Add);
                ExecuteSafely(agg, commands);
                return(then);
            }

            throw new NotSupportedException("identity not supported " + id);
        }
        public IHttpActionResult ApplyInternship(string studentid, string internshipid, string status)
        {
            Applied app = db.Applieds.Where(item => item.I_Id == internshipid && item.S_Id == studentid).FirstOrDefault();

            if (app == null)
            {
                app        = new Applied();
                app.S_Id   = studentid;
                app.I_Id   = internshipid;
                app.Status = "IP";
                db.Applieds.Add(app);
            }
            else
            {
                app.Status = status;
                if (status.Equals("AP"))
                {
                    app.Internship.AvailableSeats = app.Internship.AvailableSeats - 1;
                }
                db.Entry(app).State = EntityState.Modified;
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                return(Ok("error"));
            }


            return(Ok("success"));
        }
Beispiel #9
0
        public ActionResult DeleteConfirmed(int id)
        {
            Applied applied = db.Applieds.Find(id);

            db.Applieds.Remove(applied);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #10
0
        protected override void OnApply(PageApplyEventArgs e)
        {
            if (e.ApplyBehavior == ApplyKind.Apply)
            {
                Applied?.Invoke();
            }

            base.OnApply(e);
        }
Beispiel #11
0
        public void Apply()
        {
            if (IsApplied)
                return;

            IsApplied = true;
            OnApplied();
            Applied?.Invoke(this);
        }
        public ActionResult SchoolSelection(Applicant applicant, FormCollection formCollection)
        {
            // Is the lottery closed?
            if (IsLotteryClosed()) // TODO implement this as an class-level annotation instead
            {
                return(RedirectToAction(actionName: "LotteryClosed"));
            }

            // Make sure someone isn't playing with the ID from the form
            if (!IsAuthorizedApplicant(applicant) || !IsActiveSession()) // TODO Use AOP/Annotations to do this instead
            {
                return(RedirectToAction("Index"));
            }

            // At least one program needs to be selected
            applicant = GetSessionApplicant(); // fills in the other properties, other than just Applicant ID
            var programIds = new List <int>();

            if (formCollection["programs"] == null || !formCollection["programs"].Any())
            {
                ModelState.AddModelError("programs", GoldenTicketText.NoSchoolSelected);
                viewHelper.PrepareSchoolSelectionView(ViewBag, applicant);
                return(View(applicant));
            }
            else
            {
                var programIdStrs = formCollection["programs"].Split(',').ToList();
                programIdStrs.ForEach(idStr => programIds.Add(int.Parse(idStr)));
            }

            // Remove existing applications for this user
            var applieds = database.Applieds.Where(applied => applied.ApplicantID == applicant.ID).ToList();

            applieds.ForEach(a => database.Applieds.Remove(a));

            // Add new Applied associations (between program and program)
            var populatedApplicant = database.Applicants.Find(applicant.ID);

            foreach (var programId in programIds)
            {
                var applied = new Applied();
                applied.ApplicantID = applicant.ID;
                applied.SchoolID    = programId;

                // Confirm that the program ID is within the city lived in (no sneakers into other districts)
                var program = database.Schools.Find(programId);
                if (program != null && program.City.Equals(populatedApplicant.StudentCity, StringComparison.CurrentCultureIgnoreCase))
                {
                    database.Applieds.Add(applied);
                }
            }

            database.SaveChanges();
            return(RedirectToAction("Review"));
        }
Beispiel #13
0
        public ActionResult DeleteConfirmed(int id)
        {
            if (Session["AJ"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            Applied applied = db.Applieds.Find(id);

            db.Applieds.Remove(applied);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #14
0
 public ActionResult Edit([Bind(Include = "APP_NO,APP_ReNO,APP_GenNO,APP_Status")] Applied applied)
 {
     if (ModelState.IsValid)
     {
         db.Entry(applied).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.APP_GenNO = new SelectList(db.Generations, "Gen_NO", "Gen_Name", applied.APP_GenNO);
     ViewBag.APP_ReNO  = new SelectList(db.Register_SC, "REG_IDCard", "REG_Name", applied.APP_ReNO);
     return(View(applied));
 }
Beispiel #15
0
        public ActionResult Create(Applied applied)
        {
            if (ModelState.IsValid)
            {
                db.Applieds.Add(applied);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.APP_GenNO = new SelectList(db.Generations, "Gen_NO", "Gen_Name", applied.APP_GenNO);
            ViewBag.APP_ReNO  = new SelectList(db.Register_SC, "REG_IDCard", "REG_Name", applied.APP_ReNO);
            return(View(applied));
        }
Beispiel #16
0
 private void ApplyInternal()
 {
     _originalTrigger.Stop();
     _repository.SaveTrigger(_clonedTrigger);
     _clonedTrigger.Initialize();
     _clonedTrigger.AfterInitialize();
     SetTrigger(
         _clonedTrigger,
         () => {
         Applied?.Invoke();
         IsModified = false;
     });
 }
Beispiel #17
0
 public ActionResult Create(Register_SC register_SC)
 {
     try
     {
         var chkIDCard = db.Register_SC.FirstOrDefault(x => x.REG_IDCard == register_SC.REG_IDCard);
         if (Convert.ToInt32(Session["IDSC"]) == 0)
         {
             if (chkIDCard == null)
             {
                 db.Register_SC.Add(register_SC);
                 Session["Errormessage"] = "สมัครได้";
                 db.SaveChanges();
                 return(RedirectToAction("IndexUser", "Generations", new { id = 0 }));
             }
             else
             {
                 Session["Errormessage"] = "บัตรซ้ำ";
                 return(RedirectToAction("Registers", "Generations", new { id = 0 }));
             }
         }
         else
         {
             var IDSC   = Convert.ToInt32(Session["IDSC"]);
             var chkApp = db.Applieds.FirstOrDefault(x =>
                                                     x.APP_ReNO == register_SC.REG_IDCard && x.APP_GenNO == IDSC);
             if (chkApp == null)
             {
                 Applied applied = new Applied()
                 {
                     APP_ReNO   = register_SC.REG_IDCard,
                     APP_GenNO  = Convert.ToInt32(Session["IDSC"]),
                     APP_Status = 3,
                     APP_Date   = DateTime.Today
                 };
                 Session.Remove("IDSC");
                 db.Applieds.Add(applied);
             }
             if (chkIDCard == null)
             {
                 db.Register_SC.Add(register_SC);
             }
             db.SaveChanges();
             return(RedirectToAction("IndexUser", "Generations", new { id = Convert.ToInt32(Session["IDSC"]) }));
         }
     }
     catch (Exception e)
     {
         return(View(register_SC));
     }
 }
Beispiel #18
0
        // GET: Applieds/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Applied applied = db.Applieds.Find(id);

            if (applied == null)
            {
                return(HttpNotFound());
            }
            return(View(applied));
        }
Beispiel #19
0
        void PublishEvents(IIdentity id, Applied then)
        {
            var arVersion = then.Version + 1;
            var arName    = IdentityConvert.ToTransportable(id);
            var name      = String.Format("{0}-{1}", arName, arVersion);
            var builder   = new EnvelopeBuilder(name);

            builder.AddString("entity", arName);

            foreach (var @event in then.Events)
            {
                builder.AddItem((object)@event);
            }
            _writer.PutMessage(_streamer.SaveEnvelopeData(builder.Build()));
        }
Beispiel #20
0
        // GET: Applieds/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Applied applied = db.Applieds.Find(id);

            if (applied == null)
            {
                return(HttpNotFound());
            }
            ViewBag.APP_GenNO = new SelectList(db.Generations, "Gen_NO", "Gen_Name", applied.APP_GenNO);
            ViewBag.APP_ReNO  = new SelectList(db.Register_SC, "REG_IDCard", "REG_Name", applied.APP_ReNO);
            return(View(applied));
        }
Beispiel #21
0
        // GET: Applieds/Delete/5
        public ActionResult Delete(int?id)
        {
            if (Session["AJ"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Applied applied = db.Applieds.Find(id);

            if (applied == null)
            {
                return(HttpNotFound());
            }
            return(View(applied));
        }
Beispiel #22
0
        /**
         * <summary>Import all the applicants from the CSV file into the system.</summary>
         */
        public List <School> ReadApplicants()
        {
            // Read the CSV
            using (var textReader = new StreamReader(csvFilePath))
            {
                var csvReader = new CsvReader(textReader);
                csvReader.Configuration.SkipEmptyRecords = true;
                csvReader.Configuration.TrimFields       = true;

                var applicants = new List <Applicant>();
                var applieds   = new List <Applied>();

                while (csvReader.Read())
                {
                    var applicant = ParseApplicant(csvReader);
                    applicants.Add(applicant);

                    // Add student to each school
                    var schoolNames = csvReader.GetField <string>("Schools Applied").Split(';');
                    foreach (var rawSchoolName in schoolNames)
                    {
                        var schoolName = rawSchoolName.Trim();
                        if (schoolName.IsEmpty())
                        {
                            continue;
                        }

                        var school = db.Schools.First(s => s.Name.Equals(schoolName, StringComparison.CurrentCultureIgnoreCase));

                        var applied = new Applied {
                            Applicant = applicant, School = school
                        };

                        applieds.Add(applied);
                    }
                }

                db.Applicants.AddRange(applicants);
                db.Applieds.AddRange(applieds);
                db.SaveChanges();
            }

            return(schools.Values.ToList());
        }
Beispiel #23
0
        void LockedChainApply(List <Block> newChain)
        {
            var localTxs           = Chain.SelectMany(x => x.Transactions);
            var remoteTxs          = newChain.SelectMany(x => x.Transactions);
            var txNotIncludeRemote =
                localTxs.Where(tx => !remoteTxs.Any(x => x.Id.Equals(tx.Id))).ToArray();

            lock (TransactionPool)
            {
                var txIds = TransactionPool.GetPool().Select(x => x.Id)
                            .Where(x => remoteTxs.Any(tx => x.Equals(tx.Id))).ToArray();
                TransactionPool.RemoveTxs(txIds);
                TransactionPool.AddTxs(txNotIncludeRemote);
            }

            lock (Chain)
            {
                Chain.Clear();
                Chain.AddRange(newChain);
            }

            UpdateUtxos();
            Applied?.Invoke();
        }
Beispiel #24
0
        public override Applied Execute(params ICommand<IIdentity>[] commands)
        {
            if (commands == null)
                throw new ArgumentNullException("commands");

            var incomingCommands = commands.ToList();
            var id = incomingCommands.First().Identity;

            var storage = StorageFactory.GetOrCreateStorage(id);
            var records = storage.GetRecords(0, int.MaxValue).ToList();
            var eventsInStore = records.Select(r => (IEvent<IIdentity>)r.Content).ToList();

            var applied = new Applied();

            if (eventsInStore.Any())
                applied.Version = records.Last().Version;

            var state = new AccountState(eventsInStore);
            var aggregate = new Account(state, applied.Events.Add);

            ExecuteSafely(aggregate, incomingCommands);

            return applied;
        }
Beispiel #25
0
 private void ApplyInternal(bool reset = true)
 {
     try
     {
         Repository.SaveScenario(_clonedScenario);
         StatisticsManager.ReRegister(_clonedScenario);
         _clonedScenario.InitializeAsync();
         _clonedScenario.AfterInitilize();
         IsModified = false;
         if (reset)
         {
             SetScenario(_clonedScenario, Applied);
         }
         else
         {
             _originalSenario = _clonedScenario; //crutch
             Applied?.Invoke();
         }
     }
     catch (Exception e)
     {
         Log.ErrorFormat(e, "Ошибка инициализации сценария {0}", _clonedScenario.Name);
     }
 }
 protected virtual void OnApplied()
 {
     Applied?.Invoke(this, EventArgs.Empty);
 }
Beispiel #27
0
 private void OnApply()
 {
     Applied?.Invoke(this, new SettingsEventArgs(this));
 }
Beispiel #28
0
        public ActionResult EditApplicant(Applicant applicant, FormCollection formCollection)
        {
            // Verify that the applicant exists
            var queriedApplicant = db.Applicants.Find(applicant.ID);

            if (queriedApplicant == null)
            {
                return(HttpNotFound());
            }

            // Empty check student and guardian information
            viewHelper.EmptyCheckStudentInformation(ModelState, applicant);
            viewHelper.EmptyCheckGuardianInformation(ModelState, applicant);

            // School selection check //TODO Make this code shareable with the parent side
            var schoolIds = new List <int>();

            if (formCollection["programs"] == null || !formCollection["programs"].Any())
            {
                ModelState.AddModelError("programs", GoldenTicketText.NoSchoolSelected);
                PrepareEditApplicantView(applicant);
                return(View(applicant));
            }
            else
            {
                var programIdStrs = formCollection["programs"].Split(',').ToList();
                programIdStrs.ForEach(idStr => schoolIds.Add(int.Parse(idStr)));
            }

            if (!ModelState.IsValid)
            {
                PrepareEditApplicantView(applicant);
                return(View(applicant));
            }

            // Remove existing applications for this user
            var applieds = db.Applieds.Where(applied => applied.ApplicantID == applicant.ID).ToList();

            applieds.ForEach(a => db.Applieds.Remove(a));

            // Add new Applied associations (between program and program)
            var populatedApplicant = db.Applicants.Find(applicant.ID);

            foreach (var programId in schoolIds)
            {
                var applied = new Applied();
                applied.ApplicantID = applicant.ID;
                applied.SchoolID    = programId;

                // Confirm that the program ID is within the city lived in (no sneakers into other districts)
                var program = db.Schools.Find(programId);
                if (program != null && program.City.Equals(populatedApplicant.StudentCity, StringComparison.CurrentCultureIgnoreCase))
                {
                    db.Applieds.Add(applied);
                }
            }

            // Save changes to the database
            db.Applicants.AddOrUpdate(applicant);
            db.SaveChanges();

            return(RedirectToAction("ViewApplicant", new{ id = applicant.ID }));
        }
        protected override void OnApply(PageApplyEventArgs e)
        {
            base.OnApply(e);

            Applied?.Invoke(this, EventArgs.Empty);
        }
Beispiel #30
0
 protected virtual void OnApplied(EventArgs e)
 {
     Applied?.Invoke(this, e);
 }
Beispiel #31
0
 private void OnApplied() => Applied?.Invoke(this, EventArgs.Empty);