public DeveloperResponse Read(long DeveloperId) { DeveloperResponse response = new DeveloperResponse(); try { using (IDbConnection conn = GetConnection()) { var result = conn.Get <Developers>(DeveloperId); if (result != null) { response.Status = true; response.Description = "Successful"; response.developer = result; } else { response.Status = false; response.Description = "No data"; } } } catch (Exception ex) { response.Status = false; response.Description = ex.Message; } return(response); }
public DeveloperResponse ReadByEmail(string Email) { DeveloperResponse response = new DeveloperResponse(); try { using (IDbConnection conn = GetConnection()) { var result = conn.GetList <Developers>("Where Email = ?Email", new { Email }).FirstOrDefault(); if (result != null) { response.Status = true; response.Description = "Successful"; response.developer = result; } else { response.Status = false; response.Description = "No data"; } } } catch (Exception ex) { response.Status = false; response.Description = ex.Message; } return(response); }
public ActionResult <DeveloperResponse> FetchByEmail(string email) { DeveloperResponse developer = new DeveloperResponse(); try { //initialize response DeveloperResponse response = new DeveloperResponse(); //Check for existence of unique identifiers (email and phone) if (!Store.CheckExistence(e => e.Email, email.ToLower())) { return(NotFound(new { Message = Constants.Non_Exist })); } response.Data = Store.FetchOne(d => d.Email, email.ToLower()); //prepare response response.Status = true; return(Ok(response)); } catch (Exception ex) { Log.LogError(ex); return(StatusCode(500, ex.ToString())); } }
public DeveloperResponse Authenticate(Login login) { DeveloperResponse response = new DeveloperResponse(); try { using (IDbConnection conn = GetConnection()) { var result = conn.GetList <Developers>("Where Email = ?Email and Password = ?Password", login).FirstOrDefault(); if (result != null) { response.Status = true; response.Description = "Successful"; response.developer = result; } else { response.Status = false; response.Description = "Invalid Email / Password"; } } } catch (Exception ex) { response.Status = false; response.Description = ex.Message; } return(response); }
public void Valid_Developer_Returns_OkResponse() { Random ran = new Random(); // Arrange Developer developer = new Developer { Guid = "5c1937cecaa4373dc4d33709", Firstname = "Olorunfemi", Lastname = "Ajibulu", Email = "*****@*****.**", GitHub_Url = "https://github.com/fzany", LinkedIn_Url = "https://www.linkedin.com/in/fzany", Phone_Number = "07034337562", Stack = Stack.Fullstack, Platform = Platform.Mobile, Stackoverflow_Url = "https://stackoverflow.com/developers/2768516/olorunfemi-ajibulu", Years_Of_Experience = 2, Sex = Sex.Male }; // Act ActionResult <DeveloperResponse> OkResponse = control.Update(developer); // Assert response is correct Assert.IsType <OkObjectResult>(OkResponse.Result); //Assert response contains Developer data DeveloperResponse developer_test = (DeveloperResponse)((OkObjectResult)OkResponse.Result).Value; Assert.NotNull(developer_test.Data); }
public void Valid_Developer_Returns_OkResponse() { Random ran = new Random(); // Arrange Developer developer = new Developer { Firstname = "Olorunfemi", Lastname = "Ajibulu", Email = $"test{Guid.NewGuid().ToString().Replace("-", "").Remove(0, 20)}@admin.com", GitHub_Url = "https://github.com/fzany", LinkedIn_Url = "https://www.linkedin.com/in/fzany", Phone_Number = $"0703433{ran.Next(1000, 9999).ToString()}", Stack = Stack.Fullstack, Platform = Platform.Mobile, Stackoverflow_Url = "https://stackoverflow.com/developers/2768516/olorunfemi-ajibulu", Years_Of_Experience = 2, Sex = Sex.Male }; // Act ActionResult <DeveloperResponse> OkResponse = control.Add(developer); // Assert response is correct Assert.IsType <OkObjectResult>(OkResponse.Result); //Assert response contains Developer data DeveloperResponse developer_test = (DeveloperResponse)((OkObjectResult)OkResponse.Result).Value; Assert.NotNull(developer_test.Data); }
public ActionResult <DeveloperResponse> Update([FromBody] Developer data) { try { //check if email is present if (string.IsNullOrWhiteSpace(data.Email)) { return(BadRequest(new { Message = Constants.Provide_Email })); } //check if email is present if (string.IsNullOrWhiteSpace(data.Phone_Number)) { return(BadRequest(new { Message = Constants.Provide_Phone })); } data.Email = data.Email.ToLower(); //Check for email formats if (!Checks.IsValidEmail(data.Email)) { return(BadRequest(new { Message = Constants.Invalid_Email })); } //check if a guid is included in the data if (string.IsNullOrWhiteSpace(data.Guid)) { return(BadRequest(new { Message = Constants.Provide_Guid })); } //check if the developer exists on the system via guid. if (!Store.CheckTestExistence(e => e.Guid, data.Guid)) { return(NotFound(new { Message = Constants.Non_Exist })); } //Update the Contact MongoDB.Driver.IMongoQuery query = Query <Developer> .EQ(d => d.Guid, data.Guid); MongoDB.Driver.IMongoUpdate replacement = Update <Developer> .Replace(data); context.Developer.Update(query, replacement); //initialize response data. DeveloperResponse response = new DeveloperResponse { //prepare response data Status = true, Message = Constants.Success, //return the newly inserted data from the database. Data = Store.FetchTestOne(d => d.Email, data.Email) }; return(Ok(response)); } catch (Exception ex) { Log.LogError(ex); return(StatusCode(500, ex.ToString())); } }
public ActionResult <DeveloperResponse> Add([FromBody] Developer data) { DeveloperResponse developer = new DeveloperResponse(); try { //initialize response DeveloperResponse response = new DeveloperResponse(); //check if guid is present if (!string.IsNullOrEmpty(data.Guid)) { return(BadRequest(new { Message = Constants.Remove_Guid })); } //check if email is present if (string.IsNullOrWhiteSpace(data.Email)) { return(BadRequest(new { Message = Constants.Provide_Email })); } data.Email = data.Email.ToLower(); //Check for email formats if (!Checks.IsValidEmail(data.Email)) { return(BadRequest(new { Message = Constants.Invalid_Email })); } //Check for existence of unique identifiers (email and phone) if (Store.CheckExistence(e => e.Email, data.Email)) { return(BadRequest(new { Message = Constants.Email_Exists })); } if (Store.CheckExistence(e => e.Phone_Number, data.Phone_Number)) { return(BadRequest(new { Message = Constants.Phone_Exists })); } //insert the data into the database context.Developer.Insert(data); //prepare response data response.Status = true; response.Message = Constants.Success; //return the newly inserted data from the database. response.Data = Store.FetchOne(d => d.Email, data.Email); return(Ok(response)); } catch (Exception ex) { Log.LogError(ex); return(StatusCode(500, ex.ToString())); } }
public async Task <ActionResult <DeveloperResponse> > GetDeveloperLists([FromQuery] Parameter parameter, string searchstring) { var devlist = new DeveloperResponse(); devlist.Count = _context.DeveloperLists.ToList().Count; devlist.DeveloperList = await _context.DeveloperLists.Skip((parameter.PageNumber - 1) *parameter.PageSize) .Where(d => d.FName.Contains(searchstring) || string.IsNullOrWhiteSpace(searchstring)) .Take(parameter.PageSize).ToListAsync(); return(devlist); }
public void By_known_Email_Returns_Ok_Result() { // Act ActionResult <DeveloperResponse> okResult = control.FetchByEmail("*****@*****.**"); // Assert the response code Assert.IsType <OkObjectResult>(okResult.Result); DeveloperResponse developer_test = (DeveloperResponse)((OkObjectResult)okResult.Result).Value; //Assert list is type <List<Developer> Assert.IsType <Developer>(developer_test.Data); //Assert response contains Developer data Assert.NotNull(developer_test.Data); }
public void By_known_Guid_Returns_Ok_Result() { //Arrange var guid = "5c1934130715c550800f22f3"; // Act ActionResult <DeveloperResponse> okResult = control.FetchById(guid); // Assert the response code Assert.IsType <OkObjectResult>(okResult.Result); DeveloperResponse developer_test = (DeveloperResponse)((OkObjectResult)okResult.Result).Value; //Assert list is type Developer Assert.IsType <Developer>(developer_test.Data); //Assert response contains Developer data Assert.NotNull(developer_test.Data); }
public void By_known_Email_Returns_Ok_Result_Ensure_Right_Data() { //Arrange var email = "*****@*****.**"; // Act ActionResult <DeveloperResponse> okResult = control.FetchByEmail(email); // Assert the response code Assert.IsType <OkObjectResult>(okResult.Result); DeveloperResponse developer_test = (DeveloperResponse)((OkObjectResult)okResult.Result).Value; //Assert list is type Developer Assert.IsType <Developer>(developer_test.Data); //Assert response contains Developer data Assert.NotNull(developer_test.Data); //Assert the response has the same email as the request. Assert.Equal(email, developer_test.Data.Email); }
public ActionResult <DeveloperResponse> FetchById(string guid) { try { //prepare response DeveloperResponse response = new DeveloperResponse(); //check for existence if (!Store.CheckExistence(e => e.Guid, guid)) { return(NotFound(new { Message = Constants.Non_Exist })); } response.Data = Store.FetchOne(d => d.Guid, guid); //send response response.Status = true; return(Ok(response)); } catch (Exception ex) { Log.LogError(ex); return(StatusCode(500, ex.ToString())); } }