public IActionResult CreateDropOffZone([FromBody] DropOffZoneModel model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(err => err.Errors[0].ErrorMessage))); } var affectedRows = _dropOff.CreateDropOff(model); if (affectedRows == 0) { return(BadRequest(new { error = "Failed to create zone" })); } return(Ok(new { message = "New drop off zone created!" })); } catch (SqlException sqlException) { Console.WriteLine(sqlException); return(StatusCode(500, new { error = "Something went horribly wrong" })); } catch (Exception e) { return(StatusCode(500, new { message = e.Message })); } }
public int CreateDropOff(DropOffZoneModel model) { var userClaims = _userSvc.GetUserClaims(); if (userClaims == null) { throw new InvalidCredentialException("User claims not found against token"); } const string sql = "INSERT INTO DropOffZones (PhysicalAddress, Latitude, Longitude, ProvinceId, City, StreetName, ContactName, ContactNumber, EmailAddress) VALUES (@PhysicalAddress, @Latitude, @Longitude, @ProvinceId, @City, @StreetName, @ContactName, @ContactNumber, @EmailAddress);"; int rows = _dbConnection.Connection.Execute(sql, new { model.PhysicalAddress, model.Latitude, model.Longitude, model.ProvinceId, model.City, model.StreetName, model.ContactName, model.ContactNumber, model.EmailAddress }); return(rows); }