public async Task <IHttpActionResult> PutCodePrefix(int id, CodePrefix codePrefix) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != codePrefix.ID) { return(BadRequest()); } db.Entry(codePrefix).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CodePrefixExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutPropertyInterestedUser(int id, PropertyInterestedUser propertyInterestedUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != propertyInterestedUser.ID) { return(BadRequest()); } db.Entry(propertyInterestedUser).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PropertyInterestedUserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PutSystemSetting(int id, SystemSetting systemSetting) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != systemSetting.ID) { return(BadRequest()); } db.Entry(systemSetting).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SystemSettingExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public virtual async Task <T> Create(T model) { _context.Set <T>().Add(model); await _context.SaveChangesAsync(); return(model); }
public async Task <IActionResult> ApproveProperty([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Check all attributes are there? Will the binding be successful? var userCp = HttpContext.User; var property = await _context.Property.FindAsync(id); if (property == null) { return(NotFound()); } if (TokenVerifier.CheckOfficer(userCp)) { property.PropertyStatus = Property.VerificationStatus.Approved; property.Timestamp = DateTime.Now; List <Rejection> rejections = _context.Rejection.Where(i => i.PropertyRef == id).ToList(); foreach (Rejection r in rejections) { _context.Rejection.Remove(r); } await _context.SaveChangesAsync(); return(Ok()); } return(Unauthorized()); }
public async Task <IActionResult> DeleteAppUser([FromRoute] string id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userCp = HttpContext.User; var appUser = await _context.AppUser.FindAsync(id); if (appUser == null || !TokenVerifier.CheckUser(userCp, id)) { return(NotFound()); } _context.AppUser.Remove(appUser); await _context.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> RejectProperty([FromRoute] int id, [FromBody] BasicRejection addRejection) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //Check all attributes are there? Will the binding be successful? var userCp = HttpContext.User; var property = await _context.Property.FindAsync(id); if (property == null) { return(NotFound()); } if (TokenVerifier.CheckOfficer(userCp)) { Rejection rejection = _mapper.Map <BasicRejection, Rejection>(addRejection); rejection.PropertyRef = id; rejection.Timestamp = DateTime.Now; if (!TryValidateModel(rejection)) { return(BadRequest()); } _context.Rejection.Add(rejection); property.PropertyStatus = Property.VerificationStatus.Rejected; property.Timestamp = DateTime.Now; await _context.SaveChangesAsync(); return(Ok()); } return(Unauthorized()); }
public async Task <IActionResult> OnPostAsync() { ErrorMessage = "Error : "; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (RegisterUser.Username == null) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } byte[] salt = Crypto.GenerateSalt(); byte[] hash = Crypto.GenerateHash(RegisterUser.Password, salt); AppUser AppUser = new AppUser(RegisterUser, hash, salt); TryValidateModel(AppUser); if (ModelState.IsValid) { _context.AppUser.Add(AppUser); try { await _context.SaveChangesAsync(); } catch (Exception) { if (_context.AppUser.Any(e => e.Username == AppUser.Username)) { ErrorMessage += "User already exists"; return(Page()); //new StatusCodeResult(StatusCodes.Status409Conflict); } else if (_context.AppUser.Any(e => e.Email == AppUser.Email)) { ErrorMessage += "Try a different e-mail address"; return(Page()); } else { ErrorMessage += "Oops, something went wrong. Please contact an administrator for support"; return(Page()); } } ErrorMessage = ""; var loginSuccess = _mapper.Map <AppUser, LoginSuccess>(AppUser); Response.Cookies.Append("Token", Crypto.GenerateJSONWebToken(AppUser, _appSettings)); return(Redirect("/")); } if (AppUser.Username.Length < 3 || AppUser.Username.Length > 30) { ErrorMessage += "Username must be between 3 and 30 characters long"; } else if (AppUser.Username.Length == 0) { ErrorMessage += "Please enter your First Name"; } else if (AppUser.Username.Length > 30) { ErrorMessage += "First Name must be less than 30 characters long"; } else if (AppUser.LastName.Length == 0) { ErrorMessage += "Please enter your Last Name"; } else if (AppUser.LastName.Length > 30) { ErrorMessage += "Last Name must be less than 30 characters long"; } else if (AppUser.Role != UserRole.Landlord || AppUser.Role != UserRole.Officer || AppUser.Role != UserRole.Student) { ErrorMessage += "Invalid Role"; } else if (AppUser.Email.Length == 0) { ErrorMessage += "Please enter your e-mail address"; } else if (!new EmailAddressAttribute().IsValid(AppUser.Email)) { ErrorMessage += "Invalid e-mail address"; } else { ErrorMessage += "Oops, something went wrong. Please contact an administrator for support"; } return(Page()); }