public async Task <IActionResult> Edit(int id, LostItemClaim model, IFormFile file = null) { if (id != model.Id) { return(NotFound()); } var lostItemClaim = await claimRepository.GetLostItemClaimById(id); Image image = null; if (ModelState.IsValid) { if (file != null) { if (!utility.IsSizeAllowed(file)) { ModelState.AddModelError("Photo", "Your file is too large, maximum allowed size is: 5MB"); return(View(file)); } if (!utility.IsImageExtensionAllowed(file)) { ModelState.AddModelError("Photo", "Please only file of type:.jpg, .jpeg, .gif, .png, .bmp are allowed"); return(View(file)); } var photoPath = utility.SaveImageToFolder(file); image = new Image { ImagePath = photoPath }; lostItemClaim.Image = image; } try { lostItemClaim.ItemCategory = model.ItemCategory; lostItemClaim.Description = model.Description; lostItemClaim.DateFound = model.DateFound; claimRepository.Update(lostItemClaim); claimRepository.Save(); } catch (DbUpdateConcurrencyException) { if (!claimRepository.LostItemClaimsExists(lostItemClaim.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Create(LostItemClaimViewModel model) { var user = await userManager.GetUserAsync(HttpContext.User); var lostItem = await lostItemRepository.GetLostItemById(model.LostItemId); if (user == null || user == lostItem.LostItemUser) { ModelState.AddModelError("", "You Cant Claim an Item you Logged"); return(View()); } if (ModelState.IsValid) { //Check if user has claimed Item before foreach (var clam in lostItem.LostItemClaims) { if (user.Id == clam.ApplicationUserId) { ModelState.AddModelError("", "You Cant claim an Item twice"); return(View()); } } Image image = null; if (model.Image != null) { if (!utility.IsSizeAllowed(model.Image)) { ModelState.AddModelError("Photo", "Your file is too large, maximum allowed size is: 5MB"); return(View(model)); } if (!utility.IsImageExtensionAllowed(model.Image)) { ModelState.AddModelError("Photo", "Please only file of type:.jpg, .jpeg, .gif, .png, .bmp are allowed"); return(View(model)); } var photopath = utility.SaveImageToFolder(model.Image); image = new Image { ImagePath = photopath }; } user.PhoneNumber = model.PhoneNumber; user.PhoneNumber = user.PhoneNumber ?? model.PhoneNumber; LostItemClaim claim = new LostItemClaim { ApplicationUser = user, LostItemId = model.LostItemId, Description = model.Description, DateFound = model.DateFound, WhereItemWasFound = model.WhereItemWasFound, Image = image }; claimRepository.Create(claim); // System.IO.File.WriteAllText("resetlink.txt", ConfirmEmail); //send mail var ConfirmClaim = Url.Action("Claims", "LostItem", new { area = "User", id = lostItem.Id }, Request.Scheme); var message = new Dictionary <string, string> { { "UName", $"{lostItem.LostItemUser.FirstName}" }, { "FName", $"{user.FirstName}" }, { "ClaimLink", $"{ConfirmClaim}" } }; await emailNotifier.SendEmailAsync(lostItem.LostItemUser.Email, "New Claim", message, "LostItemClaim"); claimRepository.Save(); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public void Delete(LostItemClaim entity) { context.Remove(entity); }
public void Update(LostItemClaim entity) { context.Update(entity); }
public void Create(LostItemClaim entity) { context.LostItemClaims.Add(entity); }