public bool AddActivity(LogEntryDTO logEntryDTO, UserDTO user)
        {
            logger.Info("Inside Add Activity Method");
            LogEntry logEntryEntity = new LogEntry();
            Mapper.CreateMap<LogEntryDTO, LogEntry>();
            logEntryEntity = Mapper.Map<LogEntryDTO, LogEntry>(logEntryDTO);
            if (logEntryDTO.ShoeId.HasValue)
            {
                int _shoeId = (int)logEntryDTO.ShoeId;
                Shoe shoeEntity = unitOfWork.ShoeRepository.GetByID(_shoeId);
                shoeEntity.ShoeDistance += logEntryDTO.Distance;
                logEntryEntity.Shoe = shoeEntity;
            }

            logEntryEntity.User = unitOfWork.UserRepository.GetByID(user.UserId);
            logEntryEntity.ActivityType = unitOfWork.ActivityTypesRepository.GetByID(logEntryDTO.ActivityTypesId);

            unitOfWork.LogEntryRepository.Insert(logEntryEntity);
            unitOfWork.Save();
            return true;
        }
 public LogEntryDTO GetActivity(int activityId, UserDTO user)
 {
     LogEntry le;
     le = unitOfWork.LogEntryRepository.Get(l => l.LogId == activityId && l.UserId == user.UserId).First();
     if (le == null)
     {
         return null;
     }
     LogEntryDTO leDTO = new LogEntryDTO();
     Mapper.CreateMap<LogEntry, LogEntryDTO>();
     leDTO = Mapper.Map<LogEntry, LogEntryDTO>(le);
     return leDTO;
 }
        public void UpdateActivity(LogEntryDTO logEntryDTO, UserDTO user)
        {
            LogEntry logEntryEntity = new LogEntry();
            Mapper.CreateMap<LogEntryDTO, LogEntry>();
            logEntryEntity = Mapper.Map<LogEntryDTO, LogEntry>(logEntryDTO);
            if (logEntryDTO.ShoeId.HasValue)
            {
                int _shoeId = (int)logEntryDTO.ShoeId;
                Shoe shoeEntity = unitOfWork.ShoeRepository.GetByID(_shoeId);
                shoeEntity.ShoeDistance += logEntryDTO.Distance;
                logEntryEntity.Shoe = shoeEntity;
            }

            logEntryEntity.User = unitOfWork.UserRepository.GetByID(user.UserId);
            logEntryEntity.ActivityType = unitOfWork.ActivityTypesRepository.GetByID(logEntryDTO.ActivityTypesId);

            LogEntry OldLogEntry = unitOfWork.LogEntryRepository.GetByID(logEntryEntity.LogId);
            unitOfWork.LogEntryRepository.Update(logEntryEntity, OldLogEntry);
            unitOfWork.Save();
        }
        public ActionResult AddActivity(LogEntryModel model)
        {
            if (ModelState.IsValid)
            {

                UserDTO user = (UserDTO)Session["User"];
                LogEntryDTO logEntry = new LogEntryDTO();

                logEntry.UserId = user.UserId;
                logEntry.ActivityName = model.ActivityName;
                logEntry.ActivityTypesId = model.ActivityType;

                logEntry.Calories = model.Calories;
                logEntry.Description = model.Description;
                logEntry.Distance = model.Distance;
                int hours = 0;
                if (model.hours.HasValue)
                {
                    hours = (int) model.hours;
                }

                logEntry.Duration = hours * 60 * 60 + model.minutes * 60 + model.seconds;
                logEntry.ShoeId = model.ShoeId;
                logEntry.Tags = model.Tags;
                logEntry.TimeZone = model.TimeZone;
                logger.Info("Time after timespan: " + model.StartDate.Date.ToShortDateString() + " " + model.StartTime);
                DateTime combinedStartTime = DateTime.Parse(model.StartDate.Date.ToShortDateString() + " " + model.StartTime);
                logEntry.StartTime = combinedStartTime;
                logger.Info("Activity type id: " + logEntry.ActivityTypesId);
                logger.Info("Acitivty from model: " + model.ActivityType);

                if (runningLogService.AddActivity(logEntry, user))
                {
                    return RedirectToAction("Index", "RunningLog");
                }
                else
                {
                    ViewBag.AddActivityError = "true";
                    return View();
                }
            }
            else
            {
                foreach (var item in ModelState)
                {
                    logger.Info("error key: " + item.Key);
                    var errors = item.Value.Errors;
                    foreach (var error in errors)
                    {
                        logger.Info("Error Values: " + error.ErrorMessage);
                    }

                }
                UserDTO user = (UserDTO)Session["User"];
                ViewBag.ActivityTypes = runningLogService.ActivityTypes();
                ViewBag.UserShoes = runningLogService.GetUserShoes(user);
                System.Collections.ObjectModel.ReadOnlyCollection<TimeZoneInfo> tz = TimeZoneInfo.GetSystemTimeZones();
                ViewBag.TimeZones = tz;
                ViewBag.SelectTz = user.TimeZone;
                return View();
            }
        }