public void Add_Get_Activity_Tags_From_Repository()
        {
            using (var context = new AcManContext(OptionsRandom)) {
                string randomTagName = "Tag " + Guid.NewGuid();
                var    tag           = new Tag {
                    Name = randomTagName
                };
                var activityTags = new Collection <Tag> {
                    tag
                };
                var activity = new Activity {
                    Caption = "Test activity",
                    Tags    = activityTags
                };

                var activityRepository = new ActivityRepository(context);
                var tagRepository      = new TagRepository(context);
                var tagId      = tagRepository.Add(tag);
                var activityId = activityRepository.Add(activity);

                var resultActivity = activityRepository.GetWithTags(activityId);
                Assert.IsNotNull(resultActivity.Tags);
                Assert.IsTrue(((Tag[])resultActivity.Tags)[0].Name.Equals(randomTagName));
            }
        }
        public void SyncUserActivityes(User user, DateTime startDate)
        {
            ICollection <Activity> remoteActivityes =
                _activityBpmOdataRepository.GetAllChangedBetweenDatesForUser(startDate, _endDate, user);

            _info += "RemoteActivityes: " + remoteActivityes.Count.ToString() + "; ";
            ICollection <Activity> acmanChangedActivityes =
                _activityRepository.GetUnsyncedForUser(user);

            foreach (var remoteActivity in remoteActivityes)
            {
                var acmanActivity =
                    acmanChangedActivityes
                    .Where(a => a.EndSystemRecordId == remoteActivity.EndSystemRecordId)
                    .FirstOrDefault()
                    ??
                    _activityRepository.GetByRemoteRecordId(remoteActivity.EndSystemRecordId);
                if (acmanActivity != null)
                {
                    if (acmanActivity.ModifiedOn < remoteActivity.ModifiedOn)
                    {
                        acmanChangedActivityes.Remove(acmanActivity);
                        AcmanHelper.MergeSyncedObjects(acmanActivity, remoteActivity);
                        _activityRepository.Edit(acmanActivity);
                    }
                }
                else
                {
                    _activityRepository.Add(remoteActivity);
                }
            }
            _info += "AcmanActivityes: " + acmanChangedActivityes.Count.ToString() + "; ";
            SyncAcmanActivity(acmanChangedActivityes);
        }
        public void Add_Get_Activity_From_Repository()
        {
            var userId = Guid.NewGuid();

            using (var context = new AcManContext(Options))
            {
                var userRepository     = new UserRepository(context);
                var activityRepository = new ActivityRepository(context);

                var user = new User {
                    Id   = userId,
                    Name = "Test " + userId.ToString()
                };
                var activity = new Activity
                {
                    Caption = "Test activity",
                    User    = user
                };

                userRepository.Add(user);
                var activityId = activityRepository.Add(
                    activity
                    );

                var resultActivity = activityRepository.Get(activityId);
                Assert.IsNotNull(resultActivity);
            }
        }
        public ActionResult CurrentActivity(HttpPostedFileBase file, int activityTypeId)
        {
            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                var path     = Path.Combine(Server.MapPath("~/Content/gps File/"), fileName);
                file.SaveAs(path);

                var gpsDataList = XmlFileReader(fileName);


                var distance      = CalculateDistance(gpsDataList);
                var finalDistance = Math.Round(distance, 2);

                var timeStamp = Math.Round((gpsDataList.Last().Time - gpsDataList.First().Time).TotalHours, 2);
                var avgSpeed  = Math.Round(distance / timeStamp, 2);

                var locationViewModel = new LocationViewModel();
                locationViewModel.GpsDatas = gpsDataList;
                locationViewModel.Distance = finalDistance;
                locationViewModel.Speed    = avgSpeed;
                locationViewModel.Time     = timeStamp;


                //var user = userRepository.GetUserByProfileId(WebSecurity.CurrentUserId);
                ////var user = userRepository.GetUserByProfileId(intuserID);
                //var weight = Convert.ToDouble(user.Weight);
                //var met = _metConditionRepository.GetMET(avgSpeed, activityTypeId);
                // var cal = Math.Round(CalculateCalorie( met,weight, timeStamp),2);
                var cal = Math.Round(CalculateCalorie(activityTypeId, avgSpeed, timeStamp), 2);
                if (cal == 0.0)
                {
                    return(RedirectToAction("Create", "User"));
                }

                locationViewModel.BurnedCalorie = cal;

                //@ViewBag.Fabiha = locationViewModel;
                var activity = new Activity
                {
                    Distance       = finalDistance,
                    Speed          = avgSpeed,
                    Calorie        = cal,
                    Duration       = timeStamp,
                    CreatedOn      = DateTime.Now,
                    UserProfileId  = WebSecurity.CurrentUserId,
                    FilePath       = fileName,
                    ActivityTypeId = activityTypeId
                };
                var isSuccess = _activityRepository.Add(activity);
                ViewBag.ActivityId    = activity.Id;
                ViewBag.ActivityType  = _activityTypeRepository.Get(activityTypeId).Title;
                ViewBag.UserProfileId = activity.UserProfileId;
                return(View(locationViewModel));
            }

            ViewBag.ErrorMessage = "Please Upload a Activity.gpx format File";
            return(View("CustomError"));
        }
        public IActionResult Activity(Activity activity)
        {
            var currentUserProfile = GetCurrentUserProfile();

            activity.UserProfileId = currentUserProfile.Id;
            _activityRepository.Add(activity);
            return(CreatedAtAction(nameof(Get), new { id = activity.Id }, activity));
        }
Beispiel #6
0
        public void Given_ActivityRepository_When_AddingMoreNewActivities_Then_TheActivitiesShouldBeProperlyAdded()
        {
            RunOnDatabase(sut =>
            {
                //Arrange

                var repository     = new ActivityRepository(sut);
                var activity       = Activity.Create("Swim", "Go to Vivertine", "leisure", new Guid(), new DateTime(2017, 11, 11), new DateTime(2017, 12, 11));
                var secondActivity = Activity.Create("Sing", "Study Eminem music", "leisure", new Guid(), new DateTime(2017, 10, 10), new DateTime(2017, 11, 11));
                var thirdActivity  = Activity.Create("Read Books", "Study .NET books", "study/work", new Guid(), new DateTime(2017, 2, 2), new DateTime(2017, 3, 3));

                //Act
                repository.Add(activity);
                repository.Add(secondActivity);
                repository.Add(thirdActivity);

                //Assert
                var activitys = repository.GetAll();
                Assert.AreEqual(3, activitys.Count);
            });
        }
Beispiel #7
0
        public static Guid CreateActivityToUser(AcManContext context, Guid userId)
        {
            var activityRepository = new ActivityRepository(context);
            var activity           = new Activity {
                UserId            = userId,
                Caption           = "[Acman] Test activity " + AcmanHelper.GetCurrentDateTime().ToString(),
                EndSystemRecordId = new Guid("8cb830fb-50d8-44ad-819f-133b713fce42"),
                EntityState       = AcmanEntityState.Added
            };

            return(activityRepository.Add(activity));
        }
Beispiel #8
0
        public void Given_ActivityRepository_When_DeletingMoreActivities_Then_TheActivitiesShouldBeProperlyRemoved()
        {
            RunOnDatabase(sut =>
            {
                //Arrange
                var repository     = new ActivityRepository(sut);
                var activity       = Activity.Create("Swim", "Go to Vivertine", "leisure", new Guid(), new DateTime(2017, 11, 11), new DateTime(2017, 12, 11));
                var secondActivity = Activity.Create("Poker", "Go to Las Vegas", "leisure", new Guid(), new DateTime(2017, 1, 11), new DateTime(2017, 2, 11));
                var thirdActivity  = Activity.Create("Ping Pong", "Go to Play Again", "leisure", new Guid(), new DateTime(2017, 2, 11), new DateTime(2017, 3, 11));

                //Act
                repository.Add(activity);
                repository.Add(secondActivity);
                repository.Add(thirdActivity);
                repository.Delete(activity.Id);
                repository.Delete(secondActivity.Id);
                repository.Delete(thirdActivity.Id);

                //Assert
                var activitys = repository.GetAll();
                Assert.AreEqual(0, activitys.Count);
            });
        }
Beispiel #9
0
        public void Given_ActivityRepository_When_GettingActivityById_Then_ShouldReturnCorrectActivity()
        {
            RunOnDatabase(sut =>
            {
                //Arrange
                var repository = new ActivityRepository(sut);
                var activity   = Activity.Create("Swim", "Go to Vivertine", "leisure", new Guid(), new DateTime(2017, 11, 11), new DateTime(2017, 12, 11));
                //Act
                repository.Add(activity);

                //Assert
                var returnedActivity = repository.GetById(activity.Id);
                Assert.AreEqual(activity.Id, returnedActivity.Id);
            });
        }
Beispiel #10
0
        public void Given_ActivityRepository_When_DeletingActivity_Then_TheActivityShouldBeProperlyRemoved()
        {
            RunOnDatabase(sut =>
            {
                //Arrange
                var repository = new ActivityRepository(sut);
                var activity   = Activity.Create("Swim", "Go to Vivertine", "leisure", new Guid(), new DateTime(2017, 11, 11), new DateTime(2017, 12, 11));
                //Act
                repository.Add(activity);
                repository.Delete(activity.Id);

                //Assert
                var activitys = repository.GetAll();
                Assert.AreEqual(0, activitys.Count);
            });
        }
Beispiel #11
0
        public void Given_ActivityRepository_When_AddingNewActivity_Then_TheActivityShouldBeProperlyAdded()
        {
            RunOnDatabase(sut =>
            {
                //Arrange
                var repository = new ActivityRepository(sut);
                var activity   = Activity.Create(".NET", "Study about .NET", "study/work", new Guid(), new DateTime(2017, 11, 11), new DateTime(2017, 12, 11));

                //Act
                repository.Add(activity);

                //Assert
                var activitys = repository.GetAll();
                Assert.AreEqual(1, activitys.Count);
            });
        }
        public void Add(Activity dailyActivity)
        {
            var types = activityTypeRepository.GetAll();

            var exactType = types.First(x => x.ActivityId == dailyActivity.ActivityType.ActivityId);

            dailyActivity.ActivityType = exactType;

            var roles    = projectRoleTypeRepository.GetAll();
            var roleType = roles.First(x => x.RoleId == dailyActivity.CurrentProjectRoleType.RoleId);

            dailyActivity.CurrentProjectRoleType = roleType;

            var projects     = projectRepository.GetAll();
            var exactProject = projects.First(x => x.ProjectId == dailyActivity.Project.ProjectId);

            dailyActivity.Project = exactProject;

            activityRepository.Add(dailyActivity);
        }
        public void Add_GetWithRelation_Activity_With_Account_From_Repository()
        {
            using (var context = new AcManContext(OptionsRandom)) {
                string randomAccountName = "Account " + Guid.NewGuid();
                var    account           = new Account {
                    Name = randomAccountName
                };
                var accountRepository = new AccountRepository(context);
                var accountId         = accountRepository.Add(account);

                var activity = new Activity {
                    Caption   = "Test activity",
                    AccountId = accountId
                };
                var activityRepository = new ActivityRepository(context);
                var activityId         = activityRepository.Add(activity);

                var resultActivity = activityRepository.GetWithRelation(activityId);
                Assert.IsTrue(resultActivity.AccountId == accountId);
                Assert.IsTrue(resultActivity.Account.Id == accountId);
            }
        }
        public ActionResult SaveOrEdit(Activity activity)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (activity.Id == 0)
                    {
                        ActivityRepository.Add(activity);
                    }
                    else
                    {
                        ActivityRepository.Edit(activity);
                    }
                    ActivityRepository.Save();


                    if (IsSuperAdmin)
                    {
                        return(RedirectToAction("Index", new { storeId = activity.StoreId }));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "Unable to save:" + activity);
                //Log the error (uncomment dex variable name and add a line here to write a log.
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(activity));
        }
 /// <summary>
 /// 添加活动
 /// </summary>
 /// <param name="activity"></param>
 /// <returns></returns>
 public bool AddActivity(Activity activity)
 {
     repository.Add(activity);
     return(true);
 }
        private void ProcessRepository()
        {
            var enumAction = EnumHelper.GetEnumValue <EnumRepository>(_action, EnumProp.DisplayCode, false);

            switch (enumAction)
            {
            case EnumRepository.Push:
                var activityModel = new ActivityModel
                {
                    Activity    = "Repository",
                    Action      = EnumHelper.GetEnumDisplayName(EnumRepository.Push, EnumProp.DisplayCode),
                    Description = EnumHelper.GetEnumDisplayName(EnumRepository.Push,
                                                                EnumProp.DisplayName),
                    Data = _dataJObject.ToString()
                };
                _activityRepository.Add(activityModel);
                break;

            case EnumRepository.Fork:
                var activityModelFork = new ActivityModel
                {
                    Activity    = "Repository",
                    Action      = EnumHelper.GetEnumDisplayName(EnumRepository.Fork, EnumProp.DisplayCode),
                    Description = EnumHelper.GetEnumDisplayName(EnumRepository.Fork, EnumProp.DisplayName),
                    Data        = _dataJObject.ToString()
                };
                _activityRepository.Add(activityModelFork);
                break;

            case EnumRepository.Updated:
                var activityModelUpdated = new ActivityModel
                {
                    Activity    = "Repository",
                    Action      = EnumHelper.GetEnumDisplayName(EnumRepository.Updated, EnumProp.DisplayCode),
                    Description = EnumHelper.GetEnumDisplayName(EnumRepository.Updated, EnumProp.DisplayName),
                    Data        = _dataJObject.ToString()
                };
                _activityRepository.Add(activityModelUpdated);
                break;

            case EnumRepository.Commitcommentcreated:
                var activityModelCommit = new ActivityModel
                {
                    Activity = "Repository",
                    Action   =
                        EnumHelper.GetEnumDisplayName(EnumRepository.Commitcommentcreated, EnumProp.DisplayCode),
                    Description =
                        EnumHelper.GetEnumDisplayName(EnumRepository.Commitcommentcreated, EnumProp.DisplayName),
                    Data = _dataJObject.ToString()
                };
                _activityRepository.Add(activityModelCommit);
                break;

            case EnumRepository.Commitstatuscreated:
                var activityModelCommitStatus = new ActivityModel
                {
                    Activity = "Repository",
                    Action   =
                        EnumHelper.GetEnumDisplayName(EnumRepository.Commitstatuscreated, EnumProp.DisplayCode),
                    Description =
                        EnumHelper.GetEnumDisplayName(EnumRepository.Commitstatuscreated, EnumProp.DisplayName),
                    Data = _dataJObject.ToString()
                };
                _activityRepository.Add(activityModelCommitStatus);
                break;

            case EnumRepository.Commitstatusupdated:
                var activityModelCommitStatusUpdated = new ActivityModel
                {
                    Activity = "Repository",
                    Action   =
                        EnumHelper.GetEnumDisplayName(EnumRepository.Commitstatusupdated, EnumProp.DisplayCode),
                    Description =
                        EnumHelper.GetEnumDisplayName(EnumRepository.Commitstatusupdated, EnumProp.DisplayName),
                    Data = _dataJObject.ToString()
                };
                _activityRepository.Add(activityModelCommitStatusUpdated);
                break;

            default:
                var activityModelUknown = new ActivityModel
                {
                    Activity    = "Repository",
                    Action      = _action,
                    Description = "Uknown action",
                    Data        = _dataJObject.ToString()
                };
                _activityRepository.Add(activityModelUknown);
                break;
            }
        }
        private void CopyStoreData(int copyStoreId, int newStoreId)
        {
            StoreDbContext.Configuration.ProxyCreationEnabled = false;


            try
            {
                var items = NavigationRepository.GetNavigationsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    NavigationRepository.Add(s);
                }
                NavigationRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = LocationRepository.GetLocationsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    LocationRepository.Add(s);
                }
                LocationRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = EmailListRepository.GetStoreEmailList(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    EmailListRepository.Add(s);
                }
                EmailListRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = BrandRepository.GetBrandsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    BrandRepository.Add(s);
                }
                BrandRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            try
            {
                var items = ContactRepository.GetContactsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ContactRepository.Add(s);
                }
                ContactRepository.Save();
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
            int productCategoryId = 0;

            try
            {
                var items = ProductCategoryRepository.GetProductCategoriesByStoreId(copyStoreId);
                foreach (var productCategory in items)
                {
                    var s = GeneralHelper.DataContractSerialization(productCategory);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ProductCategoryRepository.Add(s);
                    ProductCategoryRepository.Save();

                    productCategoryId = s.Id;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "ProductCategoryRepository:CopyStore");
            }

            int blogCategoryId = 0;
            int newsCategoryId = 0;

            try
            {
                var items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.BlogsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    CategoryRepository.Add(s);
                    CategoryRepository.Save();

                    blogCategoryId = s.Id;
                }

                items = CategoryRepository.GetCategoriesByStoreId(copyStoreId, StoreConstants.NewsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    CategoryRepository.Add(s);
                    CategoryRepository.Save();

                    newsCategoryId = s.Id;
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }


            try
            {
                var items = ProductRepository.GetProductsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id = 0;
                    s.ProductCategoryId = productCategoryId;
                    s.StoreId           = newStoreId;
                    ProductRepository.Add(s);
                    ProductRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.BlogsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id         = 0;
                    s.StoreId    = newStoreId;
                    s.CategoryId = blogCategoryId;
                    ContentRepository.Add(s);
                    ContentRepository.Save();
                }

                items = ContentRepository.GetContentsByStoreId(copyStoreId, "", StoreConstants.NewsType);
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id         = 0;
                    s.StoreId    = newStoreId;
                    s.CategoryId = newsCategoryId;
                    ContentRepository.Add(s);
                    ContentRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = LabelRepository.GetLabelsByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    LabelRepository.Add(s);
                    LabelRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }

            try
            {
                var items = ActivityRepository.GetActivitiesByStoreId(copyStoreId, "");
                foreach (var item in items)
                {
                    var s = GeneralHelper.DataContractSerialization(item);
                    s.Id      = 0;
                    s.StoreId = newStoreId;
                    ActivityRepository.Add(s);
                    ActivityRepository.Save();
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, "CopyStore", newStoreId);
            }
        }
 public void Add(Activity dailyActivity)
 {
     activityRepository.Add(dailyActivity);
 }
Beispiel #19
0
        public override void Update(PlanSnapshot.Changes changes)
        {
            foreach (var planNodeDo in changes.Delete)
            {
                PlanNodes.Remove(planNodeDo);

                if (planNodeDo is ActivityDO)
                {
                    ActivityRepository.Remove((ActivityDO)planNodeDo);
                }
                else if (planNodeDo is PlanDO)
                {
                    Plans.Remove((PlanDO)planNodeDo);
                }
                else if (planNodeDo is SubplanDO)
                {
                    SubPlans.Remove((SubplanDO)planNodeDo);
                }
            }

            foreach (var planNodeDo in changes.Insert)
            {
                var entity = planNodeDo.Clone();

                ClearNavigationProperties(entity);

                if (entity is ActivityDO)
                {
                    EncryptActivityCrateStorage((ActivityDO)entity);
                    ActivityRepository.Add((ActivityDO)entity);
                }
                else if (entity is PlanDO)
                {
                    Plans.Add((PlanDO)entity);
                }
                else if (entity is SubplanDO)
                {
                    SubPlans.Add((SubplanDO)entity);
                }
                else
                {
                    PlanNodes.Add(entity);
                }
            }

            foreach (var changedObject in changes.Update)
            {
                var    planNodeDo = changedObject.Node.Clone();
                object entity     = null;

                if (planNodeDo is ActivityDO)
                {
                    entity = ActivityRepository.GetByKey(planNodeDo.Id);
                    UpdateEncryptedActivityCrateStorage((ActivityDO)planNodeDo, changedObject);
                }
                else if (planNodeDo is PlanDO)
                {
                    entity = Plans.GetByKey(planNodeDo.Id);
                }
                else if (planNodeDo is SubplanDO)
                {
                    entity = SubPlans.GetByKey(planNodeDo.Id);
                }

                foreach (var changedProperty in changedObject.ChangedProperties)
                {
                    changedProperty.SetValue(entity, changedProperty.GetValue(planNodeDo));
                }
            }
        }