Esempio n. 1
0
        private void GetRefectoryFromSpreadSheet(int row, ExcelWorksheet sheet, int EventId)
        {
            Refectory h = new Refectory();

            h.Name    = (string)sheet.Cells[REFECTORY_NAME + Convert.ToString(row)].Value;
            h.EventId = EventId;
            h.Persist();
            Table t = new Table();

            t.Name        = (string)sheet.Cells[TABLE_NAME + Convert.ToString(row)].Value;
            t.RefectoryId = h.Id;
            try
            {
                t.Capacity = Convert.ToInt32(sheet.Cells[TABLE_CAPACITY + Convert.ToString(row)].Value);
            }
            catch (Exception)
            {
                t.Capacity = 0;
            }

            try
            {
                t.RegimeType = Convertors.GetRegimeType((string)sheet.Cells[TYPE_TABLE + Convert.ToString(row)].Value.ToString().ToLowerInvariant());
            }
            catch (Exception)
            {
                t.RegimeType = RegimeEnum.NONE;
            }
            t.Persist();
        }
Esempio n. 2
0
        public async Task Given_AString_WhenIsUploadInStorage_Then_Should_BeThere()
        {
            //Assert
            JObject testJObject = new JObject
            {
                { "Cpu", "Intel" },
                { "Memory", 32 },
                {
                    "Drives", new JArray
                    {
                        "DVD",
                        "SSD"
                    }
                }
            };

            using (var memoryStream = new MemoryStream())
            {
                using (var s = Convertors.GenerateStreamFromString(testJObject))
                {
                    await s.CopyToAsync(memoryStream);

                    await _sut.UploadAsync("nameTest", memoryStream);
                }
            }
            Assert.AreEqual(await _sut.ExistBlob("nameTest"), true);
        }
Esempio n. 3
0
        public List <string> GetStringListOfEmptySections()
        {
            List <string> ret = new List <string>
            {
                //Add file header
                string.Format("Evènement organisé du {1} {2} au {3} {4} dans la ville de {0}"
                              , this.CurrentEvent.Place
                              , this.CurrentEvent.StartDate.DayOfWeek
                              , this.CurrentEvent.StartDate
                              , this.CurrentEvent.EndDate.DayOfWeek
                              , this.CurrentEvent.EndDate)
            };

            if (this.ListAvailableSections.Count() == 0)
            {
                ret.Add("Plus de place disponible dans le Hall!");
                return(ret);
            }

            ret.Add("Type Section,Nom Section,Nr Siège");
            foreach (KeyValuePair <HallSectionTypeEnum, Stack <HallEntry> > elem in this.ListAvailableSections)
            {
                foreach (HallEntry hall in elem.Value)
                {
                    ret.Add(string.Format("{0},{1},{2}"
                                          , Convertors.HallSectionTypeToString(elem.Key)
                                          , this.seatsInHall[hall.HallId].Name
                                          , hall.SeatNbr));
                }
            }

            return(ret);
        }
Esempio n. 4
0
        private void GetDormFromSpreadSheet(int row, ExcelWorksheet sheet, int EventId)
        {
            Dormitory h = new Dormitory();

            h.Capacity = Convert.ToInt32(sheet.Cells[COLUMN_CAPACITE + Convert.ToString(row)].Value);
            h.Name     = (string)sheet.Cells[COLUMN_NAME + Convert.ToString(row)].Value;
            h.EventId  = EventId;

            try
            {
                h.DormType = Convertors.GetDormirtoryType((string)sheet.Cells[TYPE_DORM + Convert.ToString(row)].Value.ToString().ToLowerInvariant());
            }
            catch (Exception)
            {
                h.DormType = DormitoryTypeEnum.NONE;
            }

            try
            {
                h.DormCategory = Convertors.GetDormirtoryCategory((string)sheet.Cells[CATEGORY_DORM + Convert.ToString(row)].Value.ToString().ToLowerInvariant());
            }
            catch (Exception)
            {
                h.DormCategory = DormitoryCategoryEnum.MATELAS;
            }

            h.Persist();
        }
Esempio n. 5
0
        public List <string> GetStringListOfEmptyTables()
        {
            List <string> ret = new List <string>
            {
                //Add file header
                string.Format("Evènement organisé du {1} {2} au {3} {4} dans la ville de {0}"
                              , this.CurrentEvent.Place
                              , this.CurrentEvent.StartDate.DayOfWeek
                              , this.CurrentEvent.StartDate
                              , this.CurrentEvent.EndDate.DayOfWeek
                              , this.CurrentEvent.EndDate)
            };

            if (this.ListAvailableTables.Count() == 0)
            {
                ret.Add("Plus de place disponible dans les Réfectoires!");
                return(ret);
            }

            ret.Add("Type Table,Réfectoire,Table,Nr Siège");
            foreach (KeyValuePair <RegimeEnum, Stack <TableEntry> > elem in this.ListAvailableTables)
            {
                foreach (TableEntry table in elem.Value)
                {
                    ret.Add(string.Format("{0},{1},{2},{3}"
                                          , Convertors.RegimeToString(elem.Key)
                                          , this.refectories[table.RefectoryId].Name
                                          , this.tablesInRefs[table.TableId].Name
                                          , table.SeatNbr));
                }
            }

            return(ret);
        }
Esempio n. 6
0
        public void PrintBadgesToFile(string directoryPath, bool forceRecompute, bool printFreeSpots)
        {
            if (this.Attendees == null || !this.Attendees.Any() || forceRecompute)
            {
                GenerateAllBadges();
            }

            string        extFile          = Convertors.EventTypeToString(this.CurrentEvent.Type, true);
            List <string> temp             = GetStringListOfAssignedAttendees();
            string        outputBadgesFile = string.Format("{0}\\Donnees_Badges.csv", directoryPath);

            File.WriteAllLines(outputBadgesFile, temp.ToArray(), Encoding.Unicode);

            if (!printFreeSpots)
            {
                return;
            }

            temp = GetStringListOfEmptySections();
            string freePlacesFile = string.Format("{0}\\Liste_Sieges_Hall_Disponibles.csv", directoryPath);

            File.WriteAllLines(freePlacesFile, temp.ToArray(), Encoding.Unicode);

            temp           = GetStringListOfEmptyBeds();
            freePlacesFile = string.Format("{0}\\Liste_Lits_Dortoir_Disponibles.csv", directoryPath);
            File.WriteAllLines(freePlacesFile, temp.ToArray(), Encoding.Unicode);

            temp           = GetStringListOfEmptyTables();
            freePlacesFile = string.Format("{0}\\Liste_Tables_Refectoire_Disponibles.csv", directoryPath);
            File.WriteAllLines(freePlacesFile, temp.ToArray(), Encoding.Unicode);
        }
Esempio n. 7
0
 public EventsReceiveMessage(EventReceive message)
 {
     this.Id       = message.EventID;
     this.Channel  = message.Channel;
     this.Body     = Convertors.ToByteArray(message.Body);
     this.Metadata = message.Metadata;
     this.Tags     = Convertors.FromMapFields(message.Tags);
 }
Esempio n. 8
0
        public void Load()
        {
            var appSettings = ConfigurationManager.AppSettings;

            UtcTarget      = Convertors.ToNullableDateTime(appSettings.Get("UtcTarget"));
            WindowLocation = Convertors.ToNullablePoint(appSettings.Get("WindowLocation"));
            WindowVisible  = Convertors.ToNullableBool(appSettings.Get("WindowVisible"));
        }
        void OnCalculate(object sender, EventArgs e)
        {
            string exp     = lblRez.Text;
            var    infix   = Convertors.Str2In(exp);
            var    postfix = Convertors.In2Post(infix);
            double result  = Convertors.CalculateExpression(postfix);

            lblRez.Text = result.ToString();
        }
Esempio n. 10
0
        public void InsirtCustomer(CustomerView newCustomer)
        {
            Validator <CustomerView> .ValidateNull(newCustomer, Convertors.FirstLetterToUpper(nameof(newCustomer)));

            var customer = ConvertToCustomer(newCustomer);

            this.context.Customers.Add(customer);
            this.context.SaveChanges();
        }
        void OnElementClick(object sender, EventArgs e)
        {
            string etext = ((Button)sender).Text;

            if (lblRez.Text == "0" && !(etext == "+" || etext == "-" || etext == "*" || etext == "/" || etext == "^"))
            {
                lblRez.Text = string.Empty;
            }
            string exp = lblRez.Text + etext;

            try
            {
                var infix = Convertors.Str2In(exp);

                var infix2 = Convertors.Str2In(exp);
                if (infix2.Last.Value is Operator || infix2.Last.Value is Parenthesis && infix2.Last.Value.Val == "(")
                {
                    infix2.AddLast(new Operand(0));
                }
                int n = 0;
                foreach (var el in infix2)
                {
                    if (el is Parenthesis)
                    {
                        if (el.Val == "(")
                        {
                            ++n;
                        }
                        else
                        {
                            --n;
                        }
                    }
                }
                for (int i = 0; i < n; ++i)
                {
                    infix2.AddLast(new Parenthesis(')'));
                }
                var    postfix = Convertors.In2Post(infix2);
                double result  = Convertors.CalculateExpression(postfix);

                var sb = new StringBuilder();
                foreach (var el in infix)
                {
                    sb.Append(el.Val);
                }
                lblRez.Text = sb.ToString();
                if (etext == ".")
                {
                    lblRez.Text += ".";
                }
            }
            catch
            {
            }
        }
Esempio n. 12
0
        public void ModifyCustomer(CustomerView modifiedCustomer)
        {
            Validator <CustomerView> .ValidateNull(modifiedCustomer, Convertors.FirstLetterToUpper(nameof(modifiedCustomer)));

            var customer = this.GetCustomerById(modifiedCustomer.CustomerID);
            var values   = context.Entry(customer).CurrentValues;

            values.SetValues(modifiedCustomer);
            context.SaveChanges();
        }
Esempio n. 13
0
        void OnCalculate(object sender, EventArgs e)
        {
            string exp     = lblRez.Text;
            var    infix   = Convertors.Str2In(exp, Base);
            var    postfix = Convertors.In2Post(infix);
            double result  = Convertors.CalculateExpression(postfix);

            lblRez.Text = Convert.ToString((long)result, Base).ToUpperInvariant();

            DisplayInSystems((long)result);
        }
Esempio n. 14
0
 public ViewsFileUploader(string moduleName) : base(moduleName)
 {
     SourcePathFolder = "Views";
     FileIgnorance    = f => {
         if (ignorenceFiles.Contains(f.Name.ToLower()))
         {
             return(true);
         }
         return(false);
     };
     Convertors.Add(new CSHTMLFileConverter());
 }
Esempio n. 15
0
 public Event ToEvent()
 {
     return(new Event
     {
         EventID = this.Id,
         ClientID = this.ClientId,
         Channel = this.Channel,
         Metadata = this.Metadata,
         Body = Convertors.FromByteArray(this.Body),
         Store = false,
         Tags = { Convertors.ToMapFields(this.Tags) }
     });
 }
Esempio n. 16
0
 private void OpenBTN_Click(object sender, EventArgs e)
 {
     if (ofd.ShowDialog() != DialogResult.OK)
     {
         return;
     }
     bmp                = (Bitmap)Image.FromFile(ofd.FileName);
     tmp                = Convertors.Bitmap2Photo(bmp);
     sizeLBL.Text       = string.Format("Size: {0} {1}", tmp.Width, tmp.Height);
     widthInputTB.Text  = tmp.Width.ToString();
     heightInputTB.Text = tmp.Height.ToString();
     inputPB.Image      = Convertors.Photo2Bitmap(tmp);
 }
Esempio n. 17
0
        public CacheMapRule <T> AddMember(Expression <Func <T, RedisValue> > fetcher, string key = null)
        {
            var unaryExpression = (UnaryExpression)fetcher.Body;

            while (unaryExpression.Operand.NodeType == ExpressionType.Convert) //Strip casts
            {
                unaryExpression = (UnaryExpression)unaryExpression.Operand;
            }
            var        memberExp  = (MemberExpression)unaryExpression.Operand;
            var        accessor   = fetcher.Compile();
            var        prefixes   = new List <string>();
            MemberInfo rootMember = null;

            if (memberExp.Expression.NodeType == ExpressionType.MemberAccess)
            {
                MemberExpression subExpression = (MemberExpression)memberExp.Expression;
                do
                {
                    if (rootMember == null)
                    {
                        rootMember = subExpression.Member;
                    }
                    prefixes.Add(subExpression.Member.Name);
                    if (subExpression.Expression.NodeType != ExpressionType.MemberAccess)
                    {
                        break;
                    }
                    subExpression = (MemberExpression)subExpression.Expression;
                } while (true);
            }
            if (rootMember == null)
            {
                rootMember = memberExp.Member;
            }
            //            string strPrefix = string.Join(".", prefixes.ToArray());
            //            if (strPrefix.Length > 0) strPrefix += ".";
            //var cMember = new CacheMember(strPrefix, (PropertyInfo)memberExp.Member);
            var cMember = new CacheMember("", (PropertyInfo)rootMember);

            if (!string.IsNullOrEmpty(key))
            {
                cMember.SetKey(key);
            }
            Convertors.Add(cMember.Key, accessor);
            Members[cMember.Key] = cMember;
            var newRule = new CacheMapRule <T>(this, cMember, fetcher);

            return(newRule);
        }
Esempio n. 18
0
        private Customer GetCustomerById(string customerId)
        {
            Validator <string> .ValidateId(customerId);

            var customer = this.context.Customers.SingleOrDefault(c => c.CustomerID == customerId);

            if (customer == null)
            {
                throw new ArgumentNullException(
                          Convertors.FirstLetterToUpper(nameof(customer)),
                          $"{Convertors.FirstLetterToUpper(nameof(customer))} with id {customerId} doesn't exist.");
            }

            return(customer);
        }
Esempio n. 19
0
        private void GetSharingGroupsFromSpreadSheet(int row, ExcelWorksheet sheet, int EventId)
        {
            SharingGroup sg = new SharingGroup();

            sg.Capacity = Convert.ToInt32(sheet.Cells[TYPE_SG_CAPACITY + Convert.ToString(row)].Value);
            sg.EventId  = EventId;
            try
            {
                sg.Type = Convertors.GetSharingGroupCategory((string)sheet.Cells[TYPE_SG + Convert.ToString(row)].Value);
            }
            catch (Exception)
            {
                sg.Type = SharingGroupCategoryEnum.ADULTE;
            }
            sg.Persist();
        }
Esempio n. 20
0
        private void Filter()
        {
            using (var uow = new UnitOfWorks())
            {
                List <DataLayer.Context.Accounting> result = new List <DataLayer.Context.Accounting>();
                DateTime?startDate;
                DateTime?endDate;


                if ((int)cbCustomers.SelectedValue != 0)
                {
                    var customerID = int.Parse(cbCustomers.SelectedValue.ToString());
                    result.AddRange(uow.AccountingRepo.GetAll(a => a.TypeID_typ == reportType && a.CustomerID_Cus == customerID));
                }
                else
                {
                    result.AddRange(uow.AccountingRepo.GetAll(a => a.TypeID_typ == reportType));
                }

                if (txtFromDate.Text != "    /  /")
                {
                    startDate = Convert.ToDateTime(txtFromDate.Text);
                    startDate = Convertors.ToMiladi(startDate.Value);
                    result    = result.Where(r => r.CreationDate.Date >= startDate.Value.Date).ToList();
                }

                if (txtToDate.Text != "    /  /")
                {
                    endDate = Convert.ToDateTime(txtToDate.Text);
                    endDate = Convertors.ToMiladi(endDate.Value);
                    var sss = endDate.Value.Date;
                    result = result.Where(r => r.CreationDate.Date <= endDate.Value.Date).ToList();
                }

                //dgvReport.DefaultCellStyle.SelectionBackColor = dgvReport.DefaultCellStyle.BackColor;
                //dgvReport.DefaultCellStyle.SelectionForeColor = dgvReport.DefaultCellStyle.ForeColor;
                //dgvReport.AutoGenerateColumns = false;
                //dgvReport.DataSource = result;
                dgvReport.Rows.Clear();
                foreach (var item in result)
                {
                    var customerName = uow.CustomerRepository.GetCustomerNameById(item.CustomerID_Cus);
                    dgvReport.Rows.Add(item.AccountigID, customerName, item.Amount.ShowMoney(), item.CreationDate.ToShamsi(), item.AccountingDescription);
                }
            }
        }
Esempio n. 21
0
        private void GetHallsFromSpreadSheet(int row, ExcelWorksheet sheet, int EventId)
        {
            Hall h = new Hall();

            h.Capacity = Convert.ToInt32(sheet.Cells[COLUMN_CAPACITE + Convert.ToString(row)].Value);
            h.Name     = (string)sheet.Cells[COLUMN_NAME + Convert.ToString(row)].Value;
            h.EventId  = EventId;
            try
            {
                h.HallType = Convertors.GetHallSectionType((string)sheet.Cells[TYPE_HALL + Convert.ToString(row)].Value);
            }
            catch (Exception)
            {
                h.HallType = HallSectionTypeEnum.NONE;
            }
            h.Persist();
        }
Esempio n. 22
0
        public void Save()
        {
            try
            {
                var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var settings   = configFile.AppSettings.Settings;

                Set(settings, "UtcTarget", Convertors.ToString(UtcTarget));
                Set(settings, "WindowLocation", Convertors.ToString(WindowLocation));
                Set(settings, "WindowVisible", Convertors.ToString(WindowVisible));

                configFile.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
            }
            catch (ConfigurationErrorsException)
            {
            }
        }
Esempio n. 23
0
 /// <summary>
 /// Convert and remove registry entries pertaining to result colors.
 /// </summary>
 /// <history>
 /// [Curtis_Beard]		10/10/2006	Created
 /// </history>
 private static void ConvertResultColors()
 {
     if (Registry.CheckStartupSetting("HighlightForeColor"))
     {
         AstroGrep.Core.GeneralSettings.HighlightForeColor = Convertors.ConvertColorToString(Registry.GetStartupSetting("HighlightForeColor", ProductInformation.ApplicationColor));
         Registry.DeleteStartupSetting("HighlightForeColor");
     }
     if (Registry.CheckStartupSetting("HighlightBackColor"))
     {
         AstroGrep.Core.GeneralSettings.HighlightBackColor = Convertors.ConvertColorToString(Registry.GetStartupSetting("HighlightBackColor", System.Drawing.SystemColors.Window));
         Registry.DeleteStartupSetting("HighlightBackColor");
     }
     if (Registry.CheckStartupSetting("ResultsForeColor"))
     {
         AstroGrep.Core.GeneralSettings.ResultsForeColor = Convertors.ConvertColorToString(Registry.GetStartupSetting("ResultsForeColor", System.Drawing.SystemColors.WindowText));
         Registry.DeleteStartupSetting("ResultsForeColor");
     }
     if (Registry.CheckStartupSetting("ResultsBackColor"))
     {
         AstroGrep.Core.GeneralSettings.ResultsBackColor = Convertors.ConvertColorToString(Registry.GetStartupSetting("ResultsBackColor", System.Drawing.SystemColors.Window));
         Registry.DeleteStartupSetting("ResultsBackColor");
     }
 }
Esempio n. 24
0
        public List <string> GetStringListOfEmptyBeds()
        {
            List <string> ret = new List <string>
            {
                //Add file header
                string.Format("Evènement organisé du {1} {2} au {3} {4} dans la ville de {0}"
                              , this.CurrentEvent.Place
                              , this.CurrentEvent.StartDate.DayOfWeek
                              , this.CurrentEvent.StartDate
                              , this.CurrentEvent.EndDate.DayOfWeek
                              , this.CurrentEvent.EndDate)
            };

            if (this.ListAvailableDorms.Count() == 0)
            {
                ret.Add("Plus de lit disponible dans les dortoirs!");
                return(ret);
            }

            ret.Add("Type Dortoir,Catégorie,Nom Dortoir,Nr Lit");
            foreach (KeyValuePair <DormitoryTypeEnum, Dictionary <DormitoryCategoryEnum, Stack <DormEntry> > > elem1 in this.ListAvailableDorms)
            {
                foreach (KeyValuePair <DormitoryCategoryEnum, Stack <DormEntry> > elem2 in elem1.Value)
                {
                    foreach (DormEntry elem3 in elem2.Value)
                    {
                        ret.Add(string.Format("{0},{1},{2},{3}"
                                              , Convertors.DormitoryTypeToString(elem1.Key)
                                              , Convertors.DormitoryCategoryToString(elem2.Key)
                                              , this.bedsInDorms[elem3.DormitoryId].Name
                                              , elem3.BedNbr));
                    }
                }
            }

            return(ret);
        }
        /// <summary>
        /// Replaces all the css holders in the given text.
        /// </summary>
        /// <param name="css">Text containing holders</param>
        /// <returns>Text with holders replaced</returns>
        /// <history>
        /// [Curtis_Beard]		09/05/2006	Created
        /// [Curtis_Beard]		01/31/2012	ADD: support highlight back color option
        /// </history>
        public static string ReplaceCssHolders(string css)
        {
            css = css.Replace("%%resultback%%", System.Drawing.ColorTranslator.ToHtml(Convertors.ConvertStringToColor(AstroGrep.Core.GeneralSettings.ResultsBackColor)));
            css = css.Replace("%%resultfore%%", System.Drawing.ColorTranslator.ToHtml(Convertors.ConvertStringToColor(AstroGrep.Core.GeneralSettings.ResultsForeColor)));
            css = css.Replace("%%highlightfore%%", System.Drawing.ColorTranslator.ToHtml(Convertors.ConvertStringToColor(AstroGrep.Core.GeneralSettings.HighlightForeColor)));
            css = css.Replace("%%highlightback%%", System.Drawing.ColorTranslator.ToHtml(Convertors.ConvertStringToColor(AstroGrep.Core.GeneralSettings.HighlightBackColor)));

            return(css);
        }
Esempio n. 26
0
 public virtual bool Move(string sourcePath) => new FileHelper().MoveAll(Path.Combine(sourcePath, BasePath), Path.Combine(BasePath, SubPath), FileIgnorance, Convertors.ToArray()).Count() == 0;
Esempio n. 27
0
        public void LoadUsers(ExcelWorksheet worksheet, int EventId)
        {
            int maxEmpty   = 0;
            int currentRow = 2;

            while (maxEmpty < MAX_EMPTY_CELLS)
            {
                EventAttendee attendee = new EventAttendee();
                string        name     = (string)worksheet.Cells[COLUMN_FIRSTNAME + Convert.ToString(currentRow)].Value;
                if (!string.IsNullOrEmpty(name))
                {
                    User u = GetUserFromSpreadSheet(currentRow, worksheet);
                    attendee.EventId = EventId;
                    attendee.UserId  = u.Id;
                    try
                    {
                        attendee.TableType = Convertors.GetRegimeType((string)worksheet.Cells[COLUMN_TABLE_TYPE + Convert.ToString(currentRow)].Value);
                    }
                    catch
                    {
                        log.Info("Regime import for table failed, setting regime to none");
                        attendee.TableType = RegimeEnum.NONE;
                    }
                    try
                    {
                        attendee.SectionType = Convertors.GetHallSectionType((string)worksheet.Cells[COLUMN_HALL_TYPE + Convert.ToString(currentRow)].Value);
                    }
                    catch
                    {
                        attendee.SectionType = HallSectionTypeEnum.NONE;
                    }
                    try
                    {
                        attendee.DormCategory = Convertors.GetDormirtoryCategory((string)worksheet.Cells[COLUMN_DORM_TYPE + Convert.ToString(currentRow)].Value);
                    }
                    catch
                    {
                        attendee.SectionType = HallSectionTypeEnum.NONE;
                    }

                    attendee.Remarks = (string)worksheet.Cells[COLUMN_REMARKS + Convert.ToString(currentRow)].Value;
                    try
                    {
                        attendee.AmountPaid = Convert.ToInt32(worksheet.Cells[COLUMN_AMOUNTPAID + Convert.ToString(currentRow)].Value);
                    }
                    catch (Exception)
                    {
                        attendee.AmountPaid = 0;
                    }

                    attendee.InvitedBy = User.GetUserIdByName((string)worksheet.Cells[COLUMN_INVITED_BY + Convert.ToString(currentRow)].Value);

                    try
                    {
                        attendee.SharingCategory = Convertors.GetSharingGroupCategory((string)worksheet.Cells[COLUMN_SHARING_CATEGORY + Convert.ToString(currentRow)].Value);
                    }
                    catch
                    {
                        attendee.SharingCategory = SharingGroupCategoryEnum.ADULTE;
                    }

                    attendee.Persist();
                    maxEmpty = 0;
                }
                else
                {
                    maxEmpty++;
                }
                currentRow++;
            }
        }
Esempio n. 28
0
        private User GetUserFromSpreadSheet(int row, ExcelWorksheet sheet)
        {
            User user = new User();

            user.FirstName = (string)sheet.Cells[COLUMN_FIRSTNAME + Convert.ToString(row)].Value;
            user.LastName  = (string)sheet.Cells[COLUMN_LASTNAME + Convert.ToString(row)].Value;
            user.Sex       = (string)sheet.Cells[COLUMN_SEX + Convert.ToString(row)].Value;
            user.Level     = Convertors.GetMembershipLevel((string)sheet.Cells[COLUMN_LEVEL + Convert.ToString(row)].Value);
            user.Language  = (string)sheet.Cells[COLUMN_LANGUAGE + Convert.ToString(row)].Value;
            user.Email     = (string)sheet.Cells[COLUMN_EMAIL + Convert.ToString(row)].Value;

            if (sheet.Cells[COLUMN_PHONE + Convert.ToString(row)].Value != null)
            {
                string val;
                try
                {
                    val = (string)sheet.Cells[COLUMN_PHONE + Convert.ToString(row)].Value;
                }
                catch (InvalidCastException)
                {
                    try
                    {
                        val = Convert.ToString((string)sheet.Cells[COLUMN_PHONE + Convert.ToString(row)].Value);
                    }
                    catch (Exception)
                    {
                        val = "";
                    }
                }

                user.PhoneNumber = val;
            }

            bool isResponsible = false;

            if (sheet.Cells[COLUMN_RESPONSIBLE + Convert.ToString(row)].Value == null)
            {
                isResponsible = false;
            }
            else
            {
                string strValue = sheet.Cells[COLUMN_RESPONSIBLE + Convert.ToString(row)].Value.ToString().ToLowerInvariant();
                isResponsible = strValue.Equals("oui") ? true : false;
            }
            user.IsGroupResponsible = isResponsible;
            user.Town = (string)sheet.Cells[COLUMN_TOWN + Convert.ToString(row)].Value;
            // read zone if it is not availlable create it,
            Zone zone = new Zone();

            zone.Label  = (string)sheet.Cells[COLUMN_ZONE + Convert.ToString(row)].Value;
            zone.Id     = Zone.GetIdRefectoryIdByName(DBcontext, zone.Label);
            zone.Id     = zone.Persist();
            user.ZoneId = zone.Id;

            SousZone sousZone = new SousZone();

            sousZone.Label  = (string)sheet.Cells[COLUMN_SOUS_ZONE + Convert.ToString(row)].Value;
            sousZone.ZoneId = zone.Id;
            sousZone.Id     = sousZone.Persist();
            user.SousZoneId = sousZone.Id;

            Group group = new Group();

            group.ZoneId     = zone.Id;
            group.SousZoneId = sousZone.Id;
            group.Label      = (string)sheet.Cells[COLUMN_GROUP + Convert.ToString(row)].Value;
            group.Id         = group.Persist();
            user.GroupId     = group.Id;
            user.persist();
            return(user);
        }
Esempio n. 29
0
        public async Task <IActionResult> CreateForm([FromBody] FormModel formModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ApiResponse {
                    Status = false, ModelState = ModelState
                }));
            }

            var options = new DbContextOptionsBuilder <ContentDbContext>()
                          .UseSqlServer(new SqlConnection(_configuration.GetConnectionString("ContentDbConnection")))
                          .Options;

            using (var context = new ContentDbContext(options))
            {
                using (var transaction = context.Database.BeginTransaction())
                {
                    try
                    {
                        var generate            = new GenerateCandidate();
                        var candidateIncomplete = new Candidate
                        {
                            Email     = formModel.Email,
                            Approved  = formModel.Approved,
                            Completed = formModel.Completed
                        };

                        var candidate       = generate.Generate(formModel.BlobObject, candidateIncomplete);
                        var actualCandidate =
                            await context.Candidates.SingleOrDefaultAsync(x => x.Email.Equals(formModel.Email));

                        if (actualCandidate != null)
                        {
                            context.Candidates.Remove(actualCandidate);
                        }
                        await context.SaveChangesAsync();

                        context.Candidates.Add(candidate);
                        await context.SaveChangesAsync();

                        //Now Delete existing blob
                        if (await _storage.ExistBlob(formModel.Email))
                        {
                            await _storage.DeleteAsync(formModel.Email);
                        }

                        using (var memoryStream = new MemoryStream())
                        {
                            using (var s = Convertors.GenerateStreamFromString(formModel.BlobObject))
                            {
                                await s.CopyToAsync(memoryStream);

                                await _storage.UploadAsync(formModel.Email, memoryStream);
                            }
                        }
                        transaction.Commit();
                        return(CreatedAtRoute("GetFormsRoute", new { email = formModel.Email },
                                              new ApiResponse {
                            Status = true
                        }));
                    }
                    catch (Exception exp)
                    {
                        _logger.LogError(exp.Message);
                        return(BadRequest(new ApiResponse {
                            Status = false
                        }));
                    }
                }
            }
        }
Esempio n. 30
0
 public PagesFileUploader(string moduleName) : base(moduleName)
 {
     SourcePathFolder = "Pages";
     Convertors.Add(new CSHTMLFileConverter());
 }