Exemplo n.º 1
0
        public virtual void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
                throw new ArgumentNullException("filterContext");

            if (filterContext.HttpContext == null)
                throw new Exception("filterContext.HttpContext");

            int currentLcid = Thread.CurrentThread.CurrentCulture.LCID;
            int lcid = 1029;
            string requestLcid = filterContext.HttpContext.Request.QueryString["LCID"];
            IPrincipal user = filterContext.HttpContext.User;
            if (!String.IsNullOrEmpty(requestLcid))
            {
                filterContext.Controller.ViewBag.LCID = requestLcid;
                Int32.TryParse(requestLcid, out lcid);
            }
            else if (user.Identity.IsAuthenticated)
            {
                var db = new DefaultContext();
                UserProfile userProfile = UserProfileCache.GetDetail(db, user.Identity.Name);
                lcid = userProfile.LCID;
            }

            CultureInfo cultureInfo = CultureInfo.GetCultureInfo(lcid);
            Thread.CurrentThread.CurrentCulture = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;
        }
Exemplo n.º 2
0
        public static MeetingTitleType[] GetIndex(DefaultContext db, string sortOrder)
        {
            IQueryable<MeetingTitleType> meetingTitleTypes = db.MeetingTitleTypes.AsQueryable();

            switch (sortOrder)
            {
                default:
                    meetingTitleTypes = meetingTitleTypes.OrderBy(ba => ba.Title);
                    break;

                case TitleDescSortOrder:
                    meetingTitleTypes = meetingTitleTypes.OrderByDescending(ba => ba.Title);
                    break;

                case MeetingTypeAscSortOrder:
                    meetingTitleTypes = meetingTitleTypes.OrderBy(ba => ba.MeetingType);
                    break;

                case MeetingTypeDescSortOrder:
                    meetingTitleTypes = meetingTitleTypes.OrderByDescending(ba => ba.MeetingType);
                    break;
            }

            return meetingTitleTypes.ToArray();
        }
Exemplo n.º 3
0
        public static void SavePropertiesBagItem(DefaultContext db, string key, string value, bool saveChangesToDb)
        {
            lock (LockPropertiesBags)
            {
                PropertiesBag propertiesBag = _propertiesBags.SingleOrDefault(pb => pb.Key.Equals(key));
                if (propertiesBag == null)
                {
                    propertiesBag = new PropertiesBag { Key = key, Value = value };
                    _propertiesBags.Add(propertiesBag);
                }
                else
                {
                    propertiesBag.Value = value;
                }

                PropertiesBag dbPropertiesBag = db.PropertiesBags.Find(key);
                if (dbPropertiesBag == null)
                {
                    dbPropertiesBag = new PropertiesBag { Key = key, Value = value };
                    db.PropertiesBags.Add(dbPropertiesBag);
                }
                else
                {
                    dbPropertiesBag.Value = value;
                }

                if (saveChangesToDb)
                {
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 4
0
        public ModelStateDictionary SendEmails(DefaultContext db)
        {
            var modelStateDictionary = new ModelStateDictionary();
            UserProfile[] userProfiles = UserProfileCache.GetIndex(db);
            bool success = true;
            foreach (UserProfile userProfile in userProfiles.Where(up => !String.IsNullOrEmpty(up.Email1)))
            {
                bool partialSuccess = Mail.SendEmail(userProfile.Email1, Subject, Body, true, true);
                if (partialSuccess)
                {
                    string logMessage = String.Format("Email for user {0} with address {1} was successfully sent.", userProfile.FullName, userProfile.Email1);
                    Logger.SetLog(logMessage);
                }
                else
                {
                    string errorMessage = String.Format("Email for user {0} with address {1} was not sent.", userProfile.FullName, userProfile.Email1);
                    Logger.SetErrorLog(errorMessage);
                }

                success &= partialSuccess;
            }

            if (!success)
            {
                modelStateDictionary.AddModelError(BaseCache.EmptyField, ValidationResource.BulkMail_SomeEmailWasNotSent_ErrorMessage);
            }

            return modelStateDictionary;
        }
Exemplo n.º 5
0
 public LyconetService(DefaultContext db, int userId)
 {
     _csvData = new DataTable();
     _summaryMesage = new StringBuilder();
     _db = db;
     _userId = userId;
 }
Exemplo n.º 6
0
        public virtual void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext == null)
                throw new ArgumentNullException("filterContext");

            if (filterContext.HttpContext == null)
                throw new Exception("filterContext.HttpContext");

            AutomaticLogoutIntervalType automaticLogoutIntervalType;
            bool isUserAutomaticLogoutIntervalSet;
            IPrincipal user = filterContext.HttpContext.User;
            if (user.Identity.IsAuthenticated)
            {
                var db = new DefaultContext();
                UserProfile userProfile = UserProfileCache.GetDetail(db, user.Identity.Name);
                automaticLogoutIntervalType = userProfile.AutomaticLogoutInterval;
                isUserAutomaticLogoutIntervalSet = true;
            }
            else
            {
                automaticLogoutIntervalType = AutomaticLogoutIntervalType.SixtyMinutes;
                isUserAutomaticLogoutIntervalSet = false;
            }

            filterContext.Controller.ViewBag.IsUserAutomaticLogoutIntervalSet = isUserAutomaticLogoutIntervalSet;
            filterContext.Controller.ViewBag.UserAutomaticLogoutInterval = (int)automaticLogoutIntervalType;
        }
Exemplo n.º 7
0
        public MeetingBusinessInfoDetail(Meeting meeting, DefaultContext db, int userId, bool isAdmin)
            : base(meeting, db, userId, isAdmin)
        {
            if (meeting == null || meeting.MeetingType != MeetingType.Lgs)
                return;

            City = meeting.City;
            AddressLine1 = meeting.AddressLine1;
            MeetingType = MeetingType.Lgs;
            MeetingKind = MeetingKind.Public;
            Date = meeting.Started.Date;
            StartTime = meeting.Started.ToString("HH:mm");
            FinishTime = meeting.Finished.ToString("HH:mm");

            var attendees = new List<MeetingDetailAttendee>();
            foreach (MeetingAttendee meetingAttendee in meeting.MeetingAttendees.Where(ma => ma.AttendeeId.HasValue || ma.UserAttendeeId.HasValue))
            {
                MeetingDetailAttendee attendee;
                if (meetingAttendee.AttendeeId.HasValue)
                {
                    bool showContactAcronym = ShowContactAcronym(db, userId, meetingAttendee.Attendee.RegistrarId);
                    attendee = new MeetingDetailAttendee
                                   {
                                       MeetingAttendeeId = meetingAttendee.MeetingAttendeeId,
                                       FirstName = showContactAcronym
                                                       ? meetingAttendee.Attendee.FirstNameAcronym
                                                       : meetingAttendee.Attendee.FirstName,
                                       LastName = showContactAcronym
                                                      ? meetingAttendee.Attendee.LastNameAcronym
                                                      : meetingAttendee.Attendee.LastName,
                                       City = meetingAttendee.Attendee.CityIndexView,
                                       LyonessId = meetingAttendee.Attendee.LyonessId,
                                       Leader = meetingAttendee.Attendee.Registrar.FullNameWithoutLyonessId,
                                       AccessUnsign =
                                           isAdmin || meeting.OrganizerId == userId ||
                                           meeting.SecondaryOrganizerId == userId ||
                                           meetingAttendee.Attendee.RegistrarId == userId
                                   };
                }
                else
                {
                    attendee = new MeetingDetailAttendee
                    {
                        MeetingAttendeeId = meetingAttendee.MeetingAttendeeId,
                        FirstName = meetingAttendee.UserAttendee.FirstName,
                        LastName = meetingAttendee.UserAttendee.LastName,
                        City = meetingAttendee.UserAttendee.CityIndexView,
                        LyonessId = meetingAttendee.UserAttendee.LyonessId,
                        Leader = meetingAttendee.UserAttendee.Registrar == null
                         ? NullDisplayText
                         : meetingAttendee.UserAttendee.Registrar.FullNameWithoutLyonessId,
                        AccessUnsign = isAdmin || meeting.OrganizerId == userId || meeting.SecondaryOrganizerId == userId || meetingAttendee.UserAttendeeId == userId
                    };
                }

                attendees.Add(attendee);
            }

            MeetingAttendees = attendees.ToArray();
        }
Exemplo n.º 8
0
        public static void Insert(DefaultContext db, Video video, int[] userIds)
        {
            db.Videos.Add(video);

            VideoUserCache.InsertWithoutSave(db, video.VideoId, userIds);

            db.SaveChanges();
        }
Exemplo n.º 9
0
        public ModelStateDictionary Validate(DefaultContext db)
        {
            var modelStateDictionary = new ModelStateDictionary();

            ValidateUniqueTitle(db, ref modelStateDictionary);

            return modelStateDictionary;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Gets the user profile index for admin.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="userId">The user id.</param>
        /// <param name="searchString">The search string.</param>
        /// <param name="searchStringAccording">The search string according.</param>
        /// <param name="sortOrder">The sort order.</param>
        /// <returns>IEnumerable{UserProfileIndex}.</returns>
        public static UserProfileIndex[] GetUserProfileIndexForAdmin(DefaultContext db, int userId, string searchString, string searchStringAccording, string sortOrder)
        {
            var parameter = new SqlParameter(UserIdSqlParameter, userId);
            UserProfileIndex[] userProfiles = db.Database.SqlQuery<UserProfileIndex>(GetUserProfileIndexForAdminProcedureTemplate, parameter).ToArray();

            userProfiles = GetUserProfileIndex(userProfiles, searchString, searchStringAccording, sortOrder);
            return userProfiles;
        }
Exemplo n.º 11
0
        public static void CheckTasks(DefaultContext db)
        {
            PeopleContactTask[] peopleContactTasks = GetPeopleContactTasks(db);
            var groupedPeopleContactTasks = peopleContactTasks.GroupBy(p => p.RegistrarId, (key, g) => new { RegistrarId = key, PeopleContactTasks = g.ToArray() }).ToArray();

            foreach (var groupedPeopleContactTask in groupedPeopleContactTasks)
            {
                if (groupedPeopleContactTask.PeopleContactTasks[0].UseMail)
                {
                    var actualTasks = new StringBuilder();
                    var delayedTasks = new StringBuilder();
                    foreach (PeopleContactTask peopleContactTask in groupedPeopleContactTask.PeopleContactTasks)
                    {
                        switch (peopleContactTask.PeopleContactTaskType)
                        {
                            case PeopleContactTaskType.Actual:
                                actualTasks.AppendLine(peopleContactTask.Text);
                                break;

                            case PeopleContactTaskType.Delayed:
                                delayedTasks.AppendLine(peopleContactTask.Text);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                        }
                    }

                    if (actualTasks.Length == 0)
                    {
                        actualTasks.AppendLine(MailResource.TaskSchedulerController_ExecuteCheckTasks_NoTasks);
                    }

                    if (delayedTasks.Length == 0)
                    {
                        delayedTasks.AppendLine(MailResource.TaskSchedulerController_ExecuteCheckTasks_NoTasks);
                    }

                    string textBody = String.Format(MailResource.TaskSchedulerController_ExecuteCheckTasks_TextBody,
                                                    actualTasks, delayedTasks, Url.GetWebRootUrl());

                    Mail.SendEmail(groupedPeopleContactTask.PeopleContactTasks[0].Email1,
                                        MailResource.TaskSchedulerController_ExecuteCheckTasks_Subject, textBody,
                                        true, true);
                }

                if (groupedPeopleContactTask.PeopleContactTasks[0].UseSms && !String.IsNullOrEmpty(groupedPeopleContactTask.PeopleContactTasks[0].SmsEmail))
                {
                    string textBody =
                        String.Format(SmsResource.TaskSchedulerController_ExecuteCheckTasks_TextBody,
                                      groupedPeopleContactTask.PeopleContactTasks.Count());

                    Mail.SendEmail(groupedPeopleContactTask.PeopleContactTasks[0].SmsEmail,
                                        SmsResource.TaskSchedulerController_ExecuteCheckTasks_Subject, textBody,
                                        true, true);
                }
            }
        }
Exemplo n.º 12
0
        private void FindVideoFilePath()
        {
            if (!IsValid)
                return;

            Video video = null;
            using (var db = new DefaultContext())
            {
                if (_isAdmin && Id > 0)
                {
                    video = VideoCache.GetDetail(db, Id);
                }
                else if (!String.IsNullOrEmpty(Token))
                {
                    string decryptedToken = Cryptography.Decrypt(Token);
                    if (String.IsNullOrEmpty(decryptedToken))
                        return;

                    int videoTokenId;
                    if (!Int32.TryParse(decryptedToken, out videoTokenId) || videoTokenId < 1)
                        return;

                    VideoToken videoToken = VideoTokenCache.GetDetail(db, videoTokenId);
                    if (videoToken == null)
                        return;

                    if (!videoToken.IsPlayedByRecipient && videoToken.Sender != null && videoToken.Recipient != null)
                    {
                        DateTime timeToSend = DateTime.Now.AddSeconds(videoToken.Video.Duration);
                        string textBody = String.Format(videoToken.Video.EmailSenderBody, videoToken.Recipient.FullName, videoToken.Video.Title, timeToSend.ToString("dd. MM. yyyy HH:mm:ss"));
                        var lazyMail = new LazyMail
                                           {
                                               Address = videoToken.Sender.Email1,
                                               TextBody = textBody,
                                               TimeToSend = timeToSend
                                           };
                        LazyMailCache.InsertWithoutSave(db, lazyMail);

                        videoToken.IsPlayedByRecipient = true;

                        VideoTokenCache.Update(db, videoToken);
                    }

                    video = videoToken.Video;
                }
            }

            if (video == null)
                return;

            string videoAbsoluteFilePath = FileService.GetAbsoluteFilePath(_server, video.RelativeFilePath);
            if (!File.Exists(videoAbsoluteFilePath))
                return;

            VideoRelativeFilePath = video.RelativeFilePath;
            VideoAbsoluteFilePath = videoAbsoluteFilePath;
        }
Exemplo n.º 13
0
        protected void ValidateUniqueTitle(DefaultContext db, ref ModelStateDictionary modelStateDictionary, int? modelTypeId = null)
        {
            bool isUnique = ManualTypeCache.IsTitleUnique(db, Title, modelTypeId);
            if (isUnique)
                return;

            string errorMessage = String.Format(ValidationResource.Global_OwnUnique_ErrorMessage, FieldResource.Global_Title_Name);
            modelStateDictionary.AddModelError(BaseCache.TitleField, errorMessage);
        }
Exemplo n.º 14
0
        public ModelStateDictionary Validate(DefaultContext db)
        {
            var modelStateDictionary = new ModelStateDictionary();

            Currency[] otherCurrencies = CurrencyCache.GetIndex(db, CurrencyId);
            ValidateUniqueCurrency(otherCurrencies, ref modelStateDictionary);
            ValidateExchangeRate(ref modelStateDictionary);

            return modelStateDictionary;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the user profile index tree.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="userId">The user id.</param>
        /// <returns>IEnumerable{UserProfileIndexTree}.</returns>
        public static UserProfileIndexTree[] GetUserProfileIndexTree(DefaultContext db, int userId)
        {
            var parameter = new SqlParameter(UserIdSqlParameter, userId);
            UserProfileIndexTree[] userProfiles = db.Database.SqlQuery<UserProfileIndexTree>(GetUserProfileIndexTreeProcedureTemplate, parameter).ToArray();
            foreach (UserProfileIndexTree userProfileIndexTree in userProfiles)
            {
                userProfileIndexTree.IsEditable = !userProfileIndexTree.IsPoliciesAccepted;
            }

            return userProfiles;
        }
Exemplo n.º 16
0
        public static void SendLazyMails(DefaultContext db)
        {
            DateTime currentTime = DateTime.Now;
            LazyMail[] lazyMails = db.LazyMails.Where(lm => lm.TimeToSend <= currentTime).ToArray();
            foreach (LazyMail lazyMail in lazyMails)
            {
                Mail.SendEmail(lazyMail.Address, MailResource.TaskSchedulerController_SendLazyMails_Subject, lazyMail.TextBody, true, true);

                db.LazyMails.Remove(lazyMail);
                db.SaveChanges();
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Gets the index of the user profile.
        /// </summary>
        /// <param name="db">The db.</param>
        /// <param name="userId">The user id.</param>
        /// <param name="searchString">The search string.</param>
        /// <param name="searchStringAccording">The search string according.</param>
        /// <param name="sortOrder">The sort order.</param>
        /// <returns>IEnumerable{UserProfileIndex}.</returns>
        public static UserProfileIndex[] GetUserProfileIndex(DefaultContext db, int userId, string searchString, string searchStringAccording, string sortOrder)
        {
            var parameter = new SqlParameter(UserIdSqlParameter, userId);
            UserProfileIndex[] userProfiles = db.Database.SqlQuery<UserProfileIndex>(GetUserProfileIndexProcedureTemplate, parameter).ToArray();
            foreach (UserProfileIndex userProfileIndex in userProfiles)
            {
                userProfileIndex.IsEditable = !userProfileIndex.IsPoliciesAccepted;
            }

            userProfiles = GetUserProfileIndex(userProfiles, searchString, searchStringAccording, sortOrder);
            return userProfiles;
        }
Exemplo n.º 18
0
        public static bool Update(DefaultContext db, ref District district)
        {
            District dbDistrict = GetDetail(db, district.DistrictId);
            if (dbDistrict == null)
                return false;

            dbDistrict.CopyFrom(district);
            db.SaveChanges();

            district = dbDistrict;
            return true;
        }
Exemplo n.º 19
0
        public static bool Update(DefaultContext db, ref MeetingTitleType meetingTitleType)
        {
            MeetingTitleType dbMeetingTitleType = GetDetail(db, meetingTitleType.MeetingTitleTypeId);
            if (dbMeetingTitleType == null)
                return false;

            dbMeetingTitleType.CopyFrom(meetingTitleType);
            db.SaveChanges();

            meetingTitleType = dbMeetingTitleType;
            return true;
        }
Exemplo n.º 20
0
        public static bool Update(DefaultContext db, ref Currency currency)
        {
            Currency dbCurrency = GetDetail(db, currency.CurrencyId);
            if (dbCurrency == null)
                return false;

            dbCurrency.CopyFrom(currency);
            db.SaveChanges();

            currency = dbCurrency;
            return true;
        }
Exemplo n.º 21
0
        public static bool Update(DefaultContext db, ManualType manualType)
        {
            int manualTypeId = manualType.ManualTypeId;
            ManualType dbManualType = GetDetail(db, manualTypeId);
            if (dbManualType == null)
                return false;

            dbManualType.CopyFrom(manualType);

            db.SaveChanges();

            return true;
        }
Exemplo n.º 22
0
        public static string GetClaAccessInvoiceNumber(DefaultContext db)
        {
            string newInvoiceNumberValue;
            lock (LockClaAccessInvoiceNumber)
            {
                string invoiceNumberValue = GetPropertiesBagItem(db, ClaAccessInvoiceNumberKey);
                var invoiceNumber = new InvoiceNumber(invoiceNumberValue);
                newInvoiceNumberValue = invoiceNumber.Next();
                SavePropertiesBagItem(db, ClaAccessInvoiceNumberKey, newInvoiceNumberValue, false);
            }

            return newInvoiceNumberValue;
        }
Exemplo n.º 23
0
        public static string GetPropertiesBagItem(DefaultContext db, string key)
        {
            lock (LockPropertiesBags)
            {
                if (_propertiesBags == null)
                {
                    _propertiesBags = db.PropertiesBags.ToList();
                }

                PropertiesBag propertiesBag = _propertiesBags.SingleOrDefault(pbi => pbi.Key.Equals(key));
                return propertiesBag == null ? null : propertiesBag.Value;
            }
        }
Exemplo n.º 24
0
        public static bool Update(DefaultContext db, VideoToken videoToken)
        {
            int videoTokenId = videoToken.VideoTokenId;
            VideoToken dbVideoToken = GetDetail(db, videoTokenId);
            if (dbVideoToken == null)
                return false;

            dbVideoToken.CopyFrom(videoToken);

            db.SaveChanges();

            return true;
        }
Exemplo n.º 25
0
        public static bool Update(DefaultContext db, Manual manual)
        {
            int manualId = manual.ManualId;
            Manual dbManual = GetDetail(db, manualId);
            if (dbManual == null)
                return false;

            dbManual.CopyFrom(manual);

            db.SaveChanges();

            return true;
        }
Exemplo n.º 26
0
 public void SendApologizeMailToUsersWithAllowedMail()
 {
     using (var db = new DefaultContext())
     {
         string[] userProfileMails = db.UserProfiles.Where(up => !String.IsNullOrEmpty(up.Email1) && up.UseMail).Select(up => up.Email1).ToArray();
         foreach (string userProfileMail in userProfileMails)
         {
             Mail.SendEmail(userProfileMail, "CLA - Omluva za úkoly z testovacího prostředí",
                                 "Pěkný den,\n\nběhem testování nové verze CLA zhruba kolem 17:45 došlo několikrát ke spuštění mechanismu pro rozesílání seznamu úkolů. Úkoly mohou být zastaralé. Email obsahuje odkaz na testovací prostředí.\n\nProsím neklikejte na odkaz.\n\nJeště jednou se omlouváme a děkujeme za pochopení.\n\nS pozdravem,\n\nCLA System.",
                                 true, false);
         }
     }
 }
Exemplo n.º 27
0
        public static void InsertWithoutSave(DefaultContext db, int videoId, int[] userIds)
        {
            IEnumerable<VideoUser> videoUsers = userIds == null
                                                    ? new VideoUser[0]
                                                    : userIds.Select(ui => new VideoUser
                                                                               {
                                                                                   VideoId = videoId,
                                                                                   UserProfileId = ui
                                                                               });

            foreach (VideoUser videoUser in videoUsers)
            {
                db.VideoUsers.Add(videoUser);
            }
        }
Exemplo n.º 28
0
        public static bool Update(DefaultContext db, Video video, int[] userIds)
        {
            int videoId = video.VideoId;
            Video dbVideo = GetDetail(db, videoId);
            if (dbVideo == null)
                return false;

            dbVideo.CopyFrom(video);

            VideoUserCache.UpdateWithoutSave(db, dbVideo, userIds);

            db.SaveChanges();

            return true;
        }
Exemplo n.º 29
0
        public static VideoToken Insert(DefaultContext db, int videoId, int senderId, int recipientId)
        {
            var videoToken = new VideoToken
                                 {
                                     Expired = DateTime.Now.AddHours(Properties.Settings.Default.VideoTokenExpirationHours),
                                     VideoId = videoId,
                                     SenderId = senderId,
                                     RecipientId = recipientId
                                 };

            db.VideoTokens.Add(videoToken);

            db.SaveChanges();

            return videoToken;
        }
Exemplo n.º 30
0
        public void GetInvoiceTest()
        {
            using(var db = new DefaultContext())
            {
                var userProfile = db.UserProfiles.SingleOrDefault(u => u.UserName.Equals("dzccele", StringComparison.InvariantCultureIgnoreCase));
                if (userProfile == null)
                    throw new Exception("UserProfile cannot be null.");

                var bankAccountForClaAccess = BankAccountCache.GetDetail(db, BankAccountType.ApplicationAccess, userProfile.ClaAccessCurrency);
                var currentDate = DateTime.Now.Date;
                string invoiceNumber;
                string invoiceHtml = BankAccountCommon.GetInvoice(db, userProfile, bankAccountForClaAccess, currentDate, out invoiceNumber);

                File.WriteAllText("Invoice.html", invoiceHtml);
            }
        }