public ActionResult Create(ActivityDto dto, HttpPostedFileBase[] files)
        {
            var user = _userRepository.GetById(Convert.ToInt32(User.Identity.Name));
            var activity = new Activity
            {
                Description = dto.Description,
                Type = dto.Type,
                User = user,
                Distance = dto.Distance,
                Duration = dto.Duration
            };

            // Save attachments
            foreach (var file in files)
            {
                if (file == null)
                    continue;

                var fileName = Path.GetFileName(file.FileName);

                var attachment = new Attachment
                {
                    MediaType = file.ContentType,
                    Size = file.ContentLength,
                    Path = String.Format("attachments/{0}/{1}/{2}", user.Id, DateTime.Now.ToString("yyyy-MM-dd"), fileName),
                    User = user
                };

                _attachmentStorage.Save(attachment.Path, file.InputStream);
                _attachmentRepository.Save(attachment);

                activity.Attachments.Add(attachment);
            }

            _activityRepository.Save(activity);

            return RedirectToAction("Details", new {id = activity.Id});
        }
        public ActionResult Edit(int id, Activity editedActivity, HttpPostedFileBase[] files)
        {
            var activity = _activityRepository.GetById(id);

            if (activity == null)
                return HttpNotFound();

            if (activity.User.Id != CurrentUser.Id)
                throw new UnauthorizedAccessException();

            // Upload files
            // Save attachments
            foreach (var file in files)
            {
                if (file == null)
                    continue;

                var fileName = Path.GetFileName(file.FileName);

                var attachment = new Attachment
                {
                    MediaType = file.ContentType,
                    Size = file.ContentLength,
                    Path = String.Format("attachments/{0}/{1}/{2}", activity.User.Id, DateTime.Now.ToString("yyyy-MM-dd"), fileName),
                    User = activity.User
                };

                _attachmentStorage.Save(attachment.Path, file.InputStream);
                _attachmentRepository.Save(attachment);

                activity.Attachments.Add(attachment);
            }

            activity.Description = editedActivity.Description;
            activity.Type = editedActivity.Type;
            activity.Distance = editedActivity.Distance;
            activity.Duration = editedActivity.Duration;

            _activityRepository.Update(activity);

            return View(activity);
        }