public ActionResult Create([Bind(Exclude = "Pictures")] CreateLandmarkViewModel model) { var landmark = Mapper.Map <CreateLandmarkViewModel, Landmark>(model); 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 + "" + i)); } } var location = Mapper.Map <CreateLandmarkViewModel, Location>(model); var town = GetTown(model.Town); location.Town = town; landmark.Location = location; if (!ModelState.IsValid) { return(View(model)); } _landmarkService.Add(landmark); _landmarkService.SaveLandmark(); var notification = new Notification() { DateTime = DateTime.Now, Landmark = landmark, Type = NotificationType.Created }; _notificationService.Add(notification); _notificationService.Save(); var users = _userService.GetUsers(); users.ForEach(u => u.Notify(notification)); _userNotificationService.Save(); return(RedirectToAction("Index", "Home")); }
public IHttpActionResult MarkAsRead() { var userId = User.Identity.GetUserId(); var userNotifications = _userNotificationService .GetAll() .Where(n => n.UserId == userId && !n.IsRead) .ToList(); userNotifications.ForEach(un => un.Read()); _userNotificationService.Save(); return(Ok()); }
public IActionResult PutUserNotification(UserNotificationUM model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var userNotificationInDb = _userNotificationService.GetByID(model.ID); if (userNotificationInDb == null) { return(NotFound("ID not found!")); } _mapper.Map(model, userNotificationInDb); _userNotificationService.Save(); return(Ok("success")); } catch (Exception e) { return(BadRequest(e.Message)); } }