예제 #1
0
        public ActionResult CheckCode(int id, string code)
        {
            Landmark landmark = _landmarkService.GetLandmarkById(id);

            if (landmark.Code != code)
            {
                return(HttpNotFound());
            }
            string userId = User.Identity.GetUserId();

            _userService.IncreaseScore(userId, landmark.Points);
            _userService.AddVisit(userId, id);
            _landmarkService.IncreaseVisits(id);

            return(new EmptyResult());
        }
        public ActionResult UpdateConfirm(UpdateLandmarksViewModel model)
        {
            var landmark = _landmarkService.GetLandmarkById(model.LandmarkId);

            DeletePictures(landmark.Pictures);
            for (int i = 0; i < Request.Files.Count; i++)
            {
                var file = Request.Files[i];
                if (file.ContentLength == 0)
                {
                    break;
                }
                byte[] imageBytes = null;
                using (var binary = new BinaryReader(file.InputStream))
                {
                    imageBytes = binary.ReadBytes(file.ContentLength);
                    landmark.Pictures.Add(CreatePictures(imageBytes, model.Name + "u" + i));
                }
            }
            SetLandmarkProps(landmark, model);
            Location location = GetLocation(model.Latitude, model.Longitude);
            var      town     = GetTown(model.Town);

            location.Town     = town;
            landmark.Location = location;
//            if (!ModelState.IsValid)
//            {
//                return View(model);
//            }
            _landmarkService.SaveLandmark();
            var notification = new Notification()
            {
                DateTime = DateTime.Now,
                Landmark = landmark,
                Type     = NotificationType.Updated
            };

            _notificationService.Add(notification);
            _notificationService.Save();

            var users = _userService.GetUsers();

            users.ForEach(u => u.Notify(notification));
            _userNotificationService.Save();
            return(RedirectToAction("Index"));
        }