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 ActivityType Get(int id)
 {
     return(activityTypeRepository.Get(id));
 }