예제 #1
0
파일: Pools.cs 프로젝트: zhao223/FPS
 public void OnDestroy()
 {
     for (int i = 0; i < this.poolsArray.Count; i++)
     {
         PoolOption opt = this.poolsArray[i];
         opt.ClearAllArray();
     }
 }
예제 #2
0
        /// <summary>
        /// Добавить опрос с опциями
        /// </summary>
        /// <param name="name">название голосования</param>
        /// <param name="start">дата начала голосования</param>
        /// <param name="end">дата окончания голосования</param>
        /// <param name="description">описание</param>
        /// <param name="listOptions">список опций</param>
        /// <returns>созданное голосование в случае успеха, иначе - null</returns>
        public static Election AddInterviewWithOptions(string name, DateTime start, DateTime end, string description, List <string> listOptions)
        {
            if (GetElectionByName(name) != null)
            {
                return(null);
            }
            if (listOptions == null || listOptions.Count == 0)
            {
                return(null);
            }
            using (var db = new ElectionsDataBase())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Election elections = new Election()
                        {
                            Name           = name,
                            DateStart      = start,
                            DateEnd        = end,
                            Description    = description,
                            Voting_type_id = 1 //Interview
                        };
                        db.Elections.Add(elections);
                        db.SaveChanges();
                        foreach (var optionName in listOptions)
                        {
                            PoolOption option = DataBase.IfExistsOptionByName(optionName);
                            if (option == null)
                            {
                                option = new PoolOption()
                                {
                                    Name = optionName
                                };
                                db.PoolOptions.Add(option);
                                db.SaveChanges();
                            }

                            db.ElectionOptions.Add(new ElectionOption()
                            {
                                Election_id = elections.Id, Option_id = option.Id
                            });
                            db.SaveChanges();
                        }
                        db.SaveChanges();
                        db.Blocks.Add(new Block(elections));

                        db.SaveChanges();

                        transaction.Commit();
                        return(elections);
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        return(null);
                    }
                }
            }
        }