public PagedResult <PaymentBasketDTO> GetPaymentBaskets(GetPaymentBasketParam getPaymentBasketParam, PartialRetrievingInfo retrievingInfo)
        {
            using (var trans = Session.BeginGetTransaction())
            {
                Profile dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);

                var query = Session.QueryOver <PaymentBasket>().Where(x => x.Profile == dbProfile);


                if (getPaymentBasketParam.StartTime.HasValue)
                {
                    query = query.Where(x => x.DateTime >= getPaymentBasketParam.StartTime.Value);
                }
                if (getPaymentBasketParam.EndTime.HasValue)
                {
                    query = query.Where(x => x.DateTime <= getPaymentBasketParam.EndTime.Value);
                }
                if (getPaymentBasketParam.CustomerId.HasValue)
                {
                    Customer dbCustomer = Session.Load <Customer>(getPaymentBasketParam.CustomerId.Value);
                    query = query.Where(x => x.Customer == dbCustomer);
                }
                query.TransformUsing(new DistinctRootEntityResultTransformer());
                trans.Commit();
                return(query.ToPagedResults <PaymentBasketDTO, PaymentBasket>(retrievingInfo));
            }
        }
Beispiel #2
0
        public static Profile CreateProfile(ISession session, string username, Country country = null, Gender gender = Gender.NotSet)
        {
            Profile profile1 = new Profile();

            if (country != null)
            {
                profile1.CountryId = country.GeoId;
            }
            profile1.Privacy    = new ProfilePrivacy();
            profile1.Settings   = new ProfileSettings();
            profile1.Gender     = gender;
            profile1.UserName   = username;
            profile1.Email      = username + "@wfg.pl";
            profile1.Birthday   = DateTime.Now;
            profile1.Statistics = new ProfileStatistics();
            session.SaveOrUpdate(profile1.Statistics);
            session.SaveOrUpdate(profile1);
            ProfileDTO dto = new ProfileDTO();

            dto.Id          = profile1.Id;
            dto.UserName    = profile1.UserName;
            dto.Birthday    = profile1.Birthday;
            dto.Email       = profile1.Email;
            dto.Settings    = new ProfileSettingsDTO();
            dto.Settings.Id = profile1.Settings.Id;
            UnitTestHelper.SetProperty(dto, "Version", profile1.Version);
            profile1.Tag = dto;
            return(profile1);
        }
        public override void setupTest()
        {
            base.setupTest();
            NHibernateContextExtension wcfExtencsion = new NHibernateContextExtension(Session);

            NHibernateContext.UnitTestContext = wcfExtencsion;

            Profile profile = new Profile();

            profile.UserName            = ProfileDTO.AdministratorName;
            profile.Email               = "*****@*****.**";
            profile.Birthday            = DateTime.Now.AddYears(-30);
            profile.Privacy             = new ProfilePrivacy();
            profile.Privacy.Searchable  = false;
            profile.CountryId           = Country.GetByTwoLetters("PL").GeoId;
            profile.Licence.AccountType = AccountType.Administrator;
            insertToDatabase(profile);

            BuildDatabase();
            Session.Clear();
            manager = new SecurityManager();

            ImagesFolder = Path.Combine(Environment.CurrentDirectory, "Images");
            if (!Directory.Exists(ImagesFolder))
            {
                Directory.CreateDirectory(ImagesFolder);
            }
        }
        public static Profile CreateProfile(ISession session, string username, Country country = null, Gender gender = Gender.NotSet, AccountType accountType = AccountType.Instructor)
        {
            Profile profile1 = new Profile();

            if (country != null)
            {
                profile1.CountryId = country.GeoId;
            }
            profile1.Licence.AccountType            = accountType;
            profile1.Licence.LastPointOperationDate = DateTime.UtcNow;
            profile1.Privacy    = new ProfilePrivacy();
            profile1.Settings   = new ProfileSettings();
            profile1.Gender     = gender;
            profile1.UserName   = username;
            profile1.Email      = username + "@wfg.pl";
            profile1.DataInfo   = new DataInfo();
            profile1.Birthday   = DateTime.Now.Date;
            profile1.Statistics = new ProfileStatistics();
            session.SaveOrUpdate(profile1.Statistics);
            session.SaveOrUpdate(profile1);
            ProfileDTO dto = profile1.Map <ProfileDTO>();

            profile1.Tag = dto;

            MyPlace defaultPlace = new MyPlace();

            defaultPlace.IsDefault = true;
            defaultPlace.IsSystem  = true;
            defaultPlace.Profile   = profile1;
            defaultPlace.Color     = Color.Aqua.ToColorString();
            defaultPlace.Name      = "Default";
            session.Save(defaultPlace);
            session.Flush();
            return(profile1);
        }
        protected ExerciseProfileData CreateExerciseRecord(Exercise exercise, Profile profile, Tuple <int, decimal> serie, DateTime trainingDate, Customer customer = null)
        {
            var trainingDay = new TrainingDay(trainingDate);

            trainingDay.Customer = customer;
            trainingDay.Profile  = profile;
            StrengthTrainingEntry entry = new StrengthTrainingEntry();

            entry.MyPlace = GetDefaultMyPlace(profile);
            trainingDay.AddEntry(entry);
            StrengthTrainingItem item = new StrengthTrainingItem();

            item.Exercise = exercise;
            entry.AddEntry(item);

            Serie set1 = new Serie();

            set1.RepetitionNumber = serie.Item1;
            set1.Weight           = serie.Item2;
            item.AddSerie(set1);
            insertToDatabase(trainingDay);

            ExerciseProfileData data = new ExerciseProfileData();

            data.Profile      = profile;
            data.Customer     = customer;
            data.Serie        = set1;
            data.TrainingDate = trainingDate;
            data.Repetitions  = serie.Item1;
            data.MaxWeight    = serie.Item2;
            data.Exercise     = exercise;
            insertToDatabase(data);
            return(data);
        }
Beispiel #6
0
        //public WorkoutPlanDTO VoteWorkoutPlan( WorkoutPlanDTO planDto)
        //{
        //    Log.WriteWarning("VoteWorkoutPlan: Username={0},planId={1}", SecurityInfo.SessionData.Profile.UserName, planDto.GlobalId);

        //    var session = Session;
        //    using (var tx = session.BeginTransaction())
        //    {
        //        var dbProfile = session.Load<Profile>(SecurityInfo.SessionData.Profile.Id);
        //        var planFromDb = (from p in session.Query<BodyArchitect.Model.TrainingPlan>()
        //                          where p.GlobalId == planDto.GlobalId
        //                          select p).SingleOrDefault();
        //        saveRating(SecurityInfo, planDto, dbProfile, planFromDb);

        //        tx.Commit();

        //        try
        //        {
        //            //send message only when someone else vote
        //            if (planFromDb.Profile != dbProfile)
        //            {
        //                if (planFromDb.Profile.Settings.NotificationWorkoutPlanVoted)
        //                {
        //                    string param = string.Format("{0},{1},{2},{3}", planFromDb.Name, dbProfile.UserName, DateTime.Now, planDto.UserRating);
        //                    MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification);
        //                    messageService.SendSystemMessage(param, dbProfile, planFromDb.Profile, BodyArchitect.Model.MessageType.WorkoutPlanVoted);
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            ExceptionHandler.Default.Process(ex);
        //        }

        //        session.Refresh(planFromDb);
        //        Mapper.Map<BodyArchitect.Model.TrainingPlan, WorkoutPlanDTO>(planFromDb, planDto);
        //        return planDto;
        //    }

        //}

        //public ExerciseDTO VoteExercise( ExerciseDTO exercise)
        //{
        //    Log.WriteWarning("VoteExercise: Username={0},planId={1}", SecurityInfo.SessionData.Profile.UserName, exercise.GlobalId);

        //    var session = Session;
        //    using (var tx = session.BeginTransaction())
        //    {
        //        var dbProfile = session.Load<Profile>(SecurityInfo.SessionData.Profile.Id);
        //        var planFromDb = (from p in session.Query<BodyArchitect.Model.Exercise>()
        //                          where p.GlobalId == exercise.GlobalId
        //                          select p).SingleOrDefault();
        //        saveRating(SecurityInfo, exercise, dbProfile, planFromDb);

        //        tx.Commit();

        //        try
        //        {
        //            //send message only when someone else vote
        //            if (planFromDb.Profile != null && planFromDb.Profile != dbProfile)
        //            {
        //                if (planFromDb.Profile.Settings.NotificationExerciseVoted)
        //                {
        //                    string param = string.Format("{0},{1},{2},{3}", planFromDb.Name, dbProfile.UserName, DateTime.Now, exercise.UserRating);
        //                    MessageService messageService = new MessageService(Session, SecurityInfo, Configuration, pushNotification);
        //                    messageService.SendSystemMessage(param, dbProfile, planFromDb.Profile, BodyArchitect.Model.MessageType.ExerciseVoted);
        //                }
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            ExceptionHandler.Default.Process(ex);
        //        }

        //        session.Refresh(planFromDb);
        //        Mapper.Map<BodyArchitect.Model.Exercise, ExerciseDTO>(planFromDb, exercise);
        //        return exercise;
        //    }

        //}

        float saveRating(SecurityInfo SecurityInfo, VoteParams ratingable, Profile profile, BodyArchitect.Model.IRatingable globalObject)
        {
            var session = Session;

            if (ratingable.UserRating != null)// && (ratingObject == null || ratingObject != null && ratingObject.Rating != ratingable.UserRating.Value))
            {
                var ratingObject = (from rating in session.Query <RatingUserValue>()
                                    where rating.ProfileId == profile.GlobalId && rating.RatedObjectId == globalObject.GlobalId
                                    select rating).SingleOrDefault();

                if (ratingObject == null)
                {
                    ratingObject               = new RatingUserValue();
                    ratingObject.ProfileId     = profile.GlobalId;
                    ratingObject.RatedObjectId = globalObject.GlobalId;
                }
                ratingObject.LoginData    = SecurityInfo.LoginData;
                ratingObject.Rating       = ratingable.UserRating.Value;
                ratingObject.ShortComment = ratingable.UserShortComment;
                ratingObject.VotedDate    = Configuration.TimerService.UtcNow;
                session.SaveOrUpdate(ratingObject);
                ProfileStatisticsUpdater.UpdateVotings(session, profile);
                //session.SaveOrUpdate(globalObject);
                //var res = (from t in session.Query<RatingUserValue>() where t.RatedObjectId == globalObject.GlobalId select t).Average(t => t.Rating);
                var res = session.QueryOver <RatingUserValue>().Where(t => t.RatedObjectId == globalObject.GlobalId).
                          SelectList(t => t.SelectAvg(r => r.Rating)).SingleOrDefault <double>();
                globalObject.Rating = (float)res;
                session.SaveOrUpdate(globalObject);

                return((float)res);
            }
            return(globalObject.Rating);
        }
 public void PrepareReminder(Profile dbProfile, IRemindable dtoEntry, IHasReminder entry, IHasReminder origEntry, DateTime dateTime, ReminderType type, ReminderRepetitions repetitions)
 {
     if (dtoEntry.RemindBefore.HasValue)
     {
         if (origEntry == null || origEntry.Reminder == null)
         {
             entry.Reminder = new ReminderItem();
         }
         else
         {
             entry.Reminder = origEntry.Reminder;
         }
         //entry.Reminder.ConnectedObject = entry.ToString();
         entry.Reminder.DateTime     = dateTime;
         entry.Reminder.Profile      = dbProfile;
         entry.Reminder.Type         = type;
         entry.Reminder.RemindBefore = dtoEntry.RemindBefore != TimeSpan.Zero
                                           ? dtoEntry.RemindBefore.Value
                                           : (TimeSpan?)null;
         entry.Reminder.Repetitions = repetitions;
         entry.Reminder.Name        = getReminderName(dateTime, type, dtoEntry, entry);
         Session.SaveOrUpdate(entry.Reminder);
         dbProfile.DataInfo.ReminderHash = Guid.NewGuid();
     }
     else if (origEntry != null && origEntry.Reminder != null)
     {
         Session.Delete(origEntry.Reminder);
         entry.Reminder = null;
         dbProfile.DataInfo.ReminderHash = Guid.NewGuid();
     }
 }
        public static TrainingPlan CreatePlan(ISession session, Profile profile1, string name, TrainingPlanDifficult difficult = TrainingPlanDifficult.Beginner, TrainingType type = TrainingType.Split, bool isPublished = true, string language = "en", WorkoutPlanPurpose purpose = WorkoutPlanPurpose.Mass, int days = 2)
        {
            var workoutPlan = new TrainingPlan();

            workoutPlan.GlobalId     = Guid.NewGuid();
            workoutPlan.Profile      = profile1;
            workoutPlan.Name         = name;
            workoutPlan.Purpose      = purpose;
            workoutPlan.Language     = language;
            workoutPlan.TrainingType = type;
            workoutPlan.Difficult    = difficult;
            workoutPlan.Author       = "test";
            workoutPlan.Status       = isPublished ? PublishStatus.Published : PublishStatus.Private;
            if (isPublished)
            {
                workoutPlan.PublishDate = DateTime.UtcNow;
            }
            for (int i = 0; i < days; i++)
            {
                var day = new TrainingPlanDay();
                day.Name = "Day" + i;
                workoutPlan.Days.Add(day);
                day.TrainingPlan = workoutPlan;
            }
            session.Save(workoutPlan);
            session.Flush();
            workoutPlan.Tag = Mapper.Map <TrainingPlan, Service.V2.Model.TrainingPlans.TrainingPlan>(workoutPlan);
            return(workoutPlan);
        }
Beispiel #9
0
        private TrainingPlan createPlan(Profile profile1, string name, PublishStatus status, TrainingPlanDifficult difficult, TrainingType type, params Exercise[] exercises)
        {
            var workoutPlan = new TrainingPlan();

            //workoutPlan.GlobalId = Guid.NewGuid();
            workoutPlan.Language     = "en";
            workoutPlan.Profile      = profile1;
            workoutPlan.Name         = name;
            workoutPlan.TrainingType = type;
            workoutPlan.Difficult    = difficult;
            workoutPlan.Author       = "test";

            workoutPlan.Status = status;
            if (status == PublishStatus.Published)
            {
                workoutPlan.PublishDate = DateTime.UtcNow;
            }
            BodyArchitect.Model.TrainingPlanDay day = new BodyArchitect.Model.TrainingPlanDay();
            day.Name = "day";
            workoutPlan.Days.Add(day);
            day.TrainingPlan     = workoutPlan;
            workoutPlan.Language = workoutPlan.Language;
            foreach (var exercise in exercises)
            {
                BodyArchitect.Model.TrainingPlanEntry entry = new BodyArchitect.Model.TrainingPlanEntry();
                entry.Exercise = exercise;
                day.Entries.Add(entry);
                entry.Day = day;
            }

            insertToDatabase(workoutPlan);
            workoutPlan.Tag = Mapper.Map <TrainingPlan, Service.V2.Model.TrainingPlans.TrainingPlan>(workoutPlan);
            return(workoutPlan);
        }
        protected MyPlace CreateMyPlace(string name, Profile profile, bool notForRecords = false)
        {
            var gym = new MyPlace();

            gym.Name          = name;
            gym.Profile       = profile;
            gym.Color         = Color.Aqua.ToColorString();
            gym.CreationDate  = DateTime.UtcNow;
            gym.NotForRecords = notForRecords;
            insertToDatabase(gym);
            return(gym);
        }
        protected ReminderItem CreateReminder(string name, Profile profile, DateTime dateTime, TimeSpan?remindBefore = null, ReminderRepetitions pattern = ReminderRepetitions.Once, ReminderType type = ReminderType.Custom)
        {
            var reminder = new ReminderItem();

            reminder.Name         = name;
            reminder.Profile      = profile;
            reminder.DateTime     = dateTime;
            reminder.Repetitions  = pattern;
            reminder.Type         = type;
            reminder.RemindBefore = remindBefore;
            insertToDatabase(reminder);
            return(reminder);
        }
        protected Championship CreateChampionship(Profile profile, string name, ChampionshipType type = ChampionshipType.Trojboj, ScheduleEntryState state = ScheduleEntryState.Done)
        {
            Championship championship = new Championship();

            championship.Name             = name;
            championship.MyPlace          = GetDefaultMyPlace(profile);
            championship.StartTime        = DateTime.Now;
            championship.Profile          = profile;
            championship.ChampionshipType = type;
            championship.State            = state;
            insertToDatabase(championship);

            return(championship);
        }
        public PagedResult <ReminderItemDTO> GetReminders(GetRemindersParam remindersParam, PartialRetrievingInfo pageInfo)
        {
            using (var tx = Session.BeginGetTransaction())
            {
                //DateTime now = Configuration.TimerService.UtcNow;
                Profile dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);

                //var query = Session.CreateQuery("SELECT ri FROM ReminderItem ri WHERE (ri.DateTime-ri.RemindBefore)>=?");
                //query.SetDateTime(0, now);
                //var query = Session.CreateQuery("SELECT ri.DateTime-ri.RemindBefore FROM ReminderItem ri ");
                //var test=query.List<object>();
                //take all reminders from one week since current time

                var query = Session.QueryOver <ReminderItem>().Where(x => x.Profile == dbProfile);

                //if(remindersParam.ValidForTime.HasValue)
                //{
                //    var langOr = Restrictions.Disjunction();
                //    langOr.Add(Restrictions.Between("DateTime", now, now + remindersParam.ValidForTime.Value + MaxRemindBefore));
                //    langOr.Add(Expression.IsNotNull("RepeatPattern"));
                //    query = query.And(langOr);
                //}

                if (remindersParam.Types != null && remindersParam.Types.Count > 0)
                {
                    var langOr = Restrictions.Disjunction();
                    foreach (var type in remindersParam.Types)
                    {
                        langOr.Add <ReminderItem>(x => x.Type == (ReminderType)type);
                    }
                    query = query.And(langOr);
                }

                //var res = query.List();

                ////now for pattern reminders
                //if (remindersParam.ValidForTime.HasValue)
                //{
                //    List<ReminderItem> reminders = new List<ReminderItem>();
                //    reminders.AddRange(evaluatePattern(res, now,remindersParam.ValidForTime.Value));
                //    reminders.AddRange(res.Where(x => string.IsNullOrWhiteSpace(x.RepeatPattern)).ToList());
                //    return reminders.Map<IList<ReminderItemDTO>>();
                //}
                //return res.Map<IList<ReminderItemDTO>>();
                var listPack = query.ToPagedResults <ReminderItemDTO, ReminderItem>(pageInfo);
                tx.Commit();
                return(listPack);
            }
        }
Beispiel #14
0
        public static FriendInvitationDTO ConvertFriendInvitation(Profile profileDb, FriendInvitation invitation)
        {
            FriendInvitationDTO dto = Mapper.Map <FriendInvitation, FriendInvitationDTO>(invitation);

            //we don't need to send the same user who invoke this method
            if (invitation.Invited == profileDb)
            {
                dto.Invited = null;
            }
            else
            {
                dto.Inviter = null;
            }
            return(dto);
        }
        protected Customer CreateCustomer(string name, Profile profile, Profile connectedProfile = null, Gender gender = Gender.Male, string email = null, string phone = null, DateTime?birthday = null)
        {
            Customer customer = new Customer();

            customer.FirstName        = customer.LastName = name;
            customer.Profile          = profile;
            customer.Settings         = new CustomerSettings();
            customer.ConnectedAccount = connectedProfile;
            customer.Gender           = gender;
            customer.Birthday         = birthday;
            customer.Email            = email;
            customer.PhoneNumber      = phone;
            insertToDatabase(customer);
            return(customer);
        }
        protected CustomerGroup CreateCustomerGroup(string name, Profile profile, int maxCustomers = 10, params Customer[] members)
        {
            CustomerGroup group = new CustomerGroup();

            group.Name       = name;
            group.Profile    = profile;
            group.Color      = Color.Aqua.ToColorString();
            group.MaxPersons = maxCustomers;
            foreach (var customer in members)
            {
                group.Customers.Add(customer);
            }

            insertToDatabase(group);
            return(group);
        }
        protected Message CreateMessage(Profile sender, Profile receiver, DateTime?dateTime = null)
        {
            Message msg = new Message();

            msg.Receiver = receiver;
            msg.Sender   = sender;
            if (!dateTime.HasValue)
            {
                dateTime = DateTime.UtcNow;
            }
            msg.CreatedDate = dateTime.Value;
            msg.Topic       = "topic";
            msg.Content     = "content";
            insertToDatabase(msg);
            return(msg);
        }
        protected Activity CreateActivity(string name, Profile profile, decimal price = 0, TimeSpan?duration = null)
        {
            Activity activity = new Activity();

            activity.Name    = name;
            activity.Profile = profile;
            activity.Color   = Color.Aqua.ToColorString();
            activity.Price   = price;
            if (duration == null)
            {
                duration = TimeSpan.FromMinutes(90);
            }
            activity.Duration = duration.Value;
            insertToDatabase(activity);
            return(activity);
        }
Beispiel #19
0
        public PagedResult <ActivityDTO> GetActivities(PartialRetrievingInfo retrievingInfo)
        {
            Log.WriteWarning("GetActivities:Username={0}", SecurityInfo.SessionData.Profile.UserName);
            var session = Session;


            using (var tx = session.BeginGetTransaction())
            {
                Profile _profile       = session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                var     queryExercises = session.QueryOver <Activity>().Where(x => x.Profile == _profile);


                var listPack = queryExercises.ToPagedResults <ActivityDTO, Activity>(retrievingInfo);
                tx.Commit();
                return(listPack);
            }
        }
        public PagedResult <ScheduleEntryBaseDTO> GetScheduleEntries(GetScheduleEntriesParam getScheduleEntriesParam, PartialRetrievingInfo retrievingInfo)
        {
            Log.WriteWarning("GetScheduleEntries:Username={0}", SecurityInfo.SessionData.Profile.UserName);

            if (!SecurityInfo.Licence.IsInstructor)
            {
                throw new LicenceException("This feature is allowed for Instructor account");
            }

            using (var trans = Session.BeginGetTransaction())
            {
                Profile dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                var     query     = Session.QueryOver <ScheduleEntryBase>()
                                    .Fetch(x => x.Reservations).Eager
                                    .Fetch(x => x.Reminder).Eager
                                    .Fetch(x => ((Championship)x).Categories).Eager
                                    .Where(x => x.Profile == dbProfile);


                if (getScheduleEntriesParam.EntryId.HasValue)
                {
                    query = query.Where(x => x.GlobalId == getScheduleEntriesParam.EntryId.Value);
                }
                if (getScheduleEntriesParam.ActivityId.HasValue)
                {
                    //query = query.JoinAlias(x =>((ScheduleEntry) x).Usluga, () => usluga);
                    query = query.Where(x => ((ScheduleEntry)x).Activity.GlobalId == getScheduleEntriesParam.ActivityId.Value);
                }
                if (getScheduleEntriesParam.StartTime.HasValue)
                {
                    query = query.Where(x => x.StartTime >= getScheduleEntriesParam.StartTime.Value);
                }
                if (getScheduleEntriesParam.EndTime.HasValue)
                {
                    query = query.Where(x => x.EndTime <= getScheduleEntriesParam.EndTime.Value);
                }
                query.TransformUsing(new DistinctRootEntityResultTransformer());
                trans.Commit();


                var res = query.ToPagedResults <ScheduleEntryBaseDTO, ScheduleEntryBase>(retrievingInfo);
                return(res);
            }
        }
        public static Exercise CreateExercise(ISession session, Profile profile, string name, string shortCut, ExerciseType exerciseType = ExerciseType.Klatka, MechanicsType mechanicsType = MechanicsType.Compound, ExerciseForceType forceType = ExerciseForceType.Push, ExerciseDifficult difficult = ExerciseDifficult.One, Guid?globalId = null)
        {
            if (globalId == null)
            {
                globalId = Guid.NewGuid();
            }
            Exercise exercise = new Exercise(globalId.Value);

            exercise.Profile           = profile;
            exercise.Name              = name;
            exercise.Shortcut          = shortCut;
            exercise.ExerciseType      = exerciseType;
            exercise.ExerciseForceType = forceType;
            exercise.MechanicsType     = mechanicsType;
            exercise.Difficult         = ExerciseDifficult.NotSet;
            session.Save(exercise);
            session.Flush();
            return(exercise);
        }
Beispiel #22
0
        public static Exercise CreateExercise(ISession session, Profile profile, string name, string shortCut, PublishStatus status, ExerciseType exerciseType = ExerciseType.Klatka, MechanicsType mechanicsType = MechanicsType.Compound, ExerciseForceType forceType = ExerciseForceType.Push, ExerciseDifficult difficult = ExerciseDifficult.One)
        {
            Exercise exercise = new Exercise(Guid.NewGuid());

            exercise.Profile      = profile;
            exercise.Name         = name;
            exercise.Shortcut     = shortCut;
            exercise.ExerciseType = exerciseType;
            exercise.Status       = status;
            if (status == PublishStatus.Published)
            {
                exercise.PublishDate = DateTime.UtcNow;
            }
            exercise.ExerciseForceType = forceType;
            exercise.MechanicsType     = mechanicsType;
            exercise.Difficult         = ExerciseDifficult.NotSet;
            session.Save(exercise);
            session.Flush();
            return(exercise);
        }
        public ReminderItemDTO SaveReminder(ReminderItemDTO reminder)
        {
            Log.WriteWarning("SaveReminder:Username={0},GlobalId={1}", SecurityInfo.SessionData.Profile.UserName, reminder.GlobalId);

            if (!SecurityInfo.Licence.IsPremium)
            {
                throw new LicenceException("This feature is allowed for Premium account");
            }

            var dbReminder = reminder.Map <ReminderItem>();

            using (var trans = Session.BeginSaveTransaction())
            {
                Profile dbProfile = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);

                ReminderItem db = Session.Get <ReminderItem>(reminder.GlobalId);
                if (db != null)
                {
                    if (SecurityInfo.SessionData.Profile.GlobalId != db.Profile.GlobalId)
                    {
                        throw new CrossProfileOperationException("Cannot modify Reminder for another user");
                    }
                }
                dbReminder.Profile = dbProfile;

                if (reminder.RemindBefore.HasValue && reminder.RemindBefore.Value.TotalDays > 7)
                {
                    throw new ArgumentOutOfRangeException("RemindBefore can be maximum 7 days");
                }
                int res = Session.QueryOver <ReminderItem>().Where(x => x.Name == dbReminder.Name && x.GlobalId != dbReminder.GlobalId && x.Profile == dbProfile).RowCount();
                if (res > 0)
                {
                    throw new UniqueException("Reminder with the same name is already exist");
                }

                dbReminder = Session.Merge(dbReminder);
                dbProfile.DataInfo.ReminderHash = Guid.NewGuid();
                trans.Commit();
                return(dbReminder.Map <ReminderItemDTO>());
            }
        }
        protected Payment CreatePayment(Product product, Profile profile)
        {
            var zakup = new Payment();

            zakup.DateTime          = DateTime.UtcNow;
            product.Payment         = zakup;
            zakup.Price             = product.Price;
            product.Payment.Product = product;
            var basket = new PaymentBasket();

            basket.Customer   = product.Customer;
            basket.DateTime   = DateTime.Now;
            basket.TotalPrice = product.Price;
            basket.Profile    = profile;
            basket.Payments.Add((Payment)product.Payment);
            ((Payment)product.Payment).PaymentBasket = basket;
            insertToDatabase(basket);
            insertToDatabase(product);
            Session.Flush();
            return((Payment)product.Payment);
        }
        private TrainingPlan createPlan(Profile profile1, string name, PublishStatus status, TrainingPlanDifficult difficult, TrainingType type, params Exercise[] exercises)
        {
            var plan = new BodyArchitect.Service.Model.TrainingPlans.TrainingPlan();

            var workoutPlan = new TrainingPlan();

            workoutPlan.GlobalId = Guid.NewGuid();
            workoutPlan.Language = "en";
            workoutPlan.Profile  = profile1;
            workoutPlan.Name     = plan.Name = name;
            plan.TrainingType    = (Service.Model.TrainingPlans.TrainingType)(workoutPlan.TrainingType = type);
            plan.Difficult       = (Service.Model.TrainingPlans.TrainingPlanDifficult)(workoutPlan.Difficult = difficult);
            workoutPlan.Author   = plan.Author = "test";

            workoutPlan.Status = status;
            if (status == PublishStatus.Published)
            {
                workoutPlan.PublishDate = DateTime.UtcNow;
            }
            TrainingPlanDay day = new TrainingPlanDay();

            day.Name = "day";
            plan.AddDay(day);
            plan.Language = workoutPlan.Language;
            foreach (var exercise in exercises)
            {
                TrainingPlanEntry entry = new TrainingPlanEntry();
                entry.ExerciseId = exercise.GlobalId;
                day.AddEntry(entry);
            }

            XmlSerializationTrainingPlanFormatter formatter = new XmlSerializationTrainingPlanFormatter();

            workoutPlan.PlanContent = formatter.ToXml(plan).ToString();

            Session.Save(workoutPlan);
            workoutPlan.Tag = Mapper.Map <TrainingPlan, WorkoutPlanDTO>(workoutPlan);
            return(workoutPlan);
        }
        protected Championship CreateChampionshipEx(Profile profile, string name, ChampionshipType type = ChampionshipType.Trojboj, ScheduleEntryState state = ScheduleEntryState.Done, DateTime?startDate = null, params ChampionshipCategory[] categories)
        {
            Championship championship = new Championship();

            championship.Name    = name;
            championship.MyPlace = GetDefaultMyPlace(profile);
            championship.Profile = profile;
            championship.State   = state;
            if (!startDate.HasValue)
            {
                startDate = DateTime.Now;
            }
            championship.StartTime = startDate.Value;
            foreach (var championshipCategory in categories)
            {
                championship.Categories.Add(championshipCategory);
            }

            championship.ChampionshipType = type;
            insertToDatabase(championship);

            return(championship);
        }
Beispiel #27
0
        public static TrainingPlan CreatePlan(ISession session, Profile profile1, string name, TrainingPlanDifficult difficult, TrainingType type, bool isPublished, string language, WorkoutPlanPurpose purpose, int days)
        {
            var workoutPlan = new TrainingPlan();

            workoutPlan.GlobalId     = Guid.NewGuid();
            workoutPlan.Profile      = profile1;
            workoutPlan.DaysCount    = days;
            workoutPlan.Name         = name;
            workoutPlan.Purpose      = purpose;
            workoutPlan.Language     = language;
            workoutPlan.TrainingType = type;
            workoutPlan.Difficult    = difficult;
            workoutPlan.Author       = "test";
            workoutPlan.PlanContent  = "plan content";
            workoutPlan.Status       = isPublished ? PublishStatus.Published : PublishStatus.Private;
            if (isPublished)
            {
                workoutPlan.PublishDate = DateTime.UtcNow;
            }
            session.Save(workoutPlan);
            workoutPlan.Tag = Mapper.Map <TrainingPlan, WorkoutPlanDTO>(workoutPlan);
            return(workoutPlan);
        }
        public ReminderItemDTO ReminderOperation(ReminderOperationParam remindersParam)
        {
            ReminderItemDTO res = null;

            using (var tx = Session.BeginSaveTransaction())
            {
                //DateTime now = Configuration.TimerService.UtcNow;
                Profile dbProfile  = Session.Load <Profile>(SecurityInfo.SessionData.Profile.GlobalId);
                var     dbReminder = Session.Get <ReminderItem>(remindersParam.ReminderItemId);

                if (dbReminder.Profile != dbProfile)
                {
                    throw new CrossProfileOperationException("Cannot change reminder from another user");
                }

                if (remindersParam.Operation == ReminderOperationType.Delete)
                {
                    deleteReminder(dbReminder, true);
                }
                else if (remindersParam.Operation == ReminderOperationType.CloseAfterShow)
                {
                    if (dbReminder.Repetitions == ReminderRepetitions.Once)
                    {
                        deleteReminder(dbReminder, true);
                    }
                    else
                    {
                        dbReminder.LastShown = Configuration.TimerService.UtcNow;
                        Session.Update(dbReminder);
                        res = dbReminder.Map <ReminderItemDTO>();
                    }
                }
                tx.Commit();
                return(res);
            }
        }
 public void SendLiveTile(ISession session, Profile user, object param)
 {
 }
 protected MyPlace GetDefaultMyPlace(Profile profile)
 {
     return(Session.QueryOver <MyPlace>().Where(x => x.Profile == profile && x.IsDefault).SingleOrDefault());
 }