public void GetByManagerId_should_handle_exception() { // Arrange BaseMock.ShouldThrowException = true; StaffResponse expectedResponse = new() { Status = new BaseResponse { Code = Code.UnknownError, ErrorMessage = "An error occured while loading work periods data" } }; ByPersonIdRequest request = new() { PersonId = _staff2.ManagerId }; LogData expectedLog = new() { CallSide = nameof(StaffService), CallerMethodName = nameof(_staffService.GetByManagerId), CreatedOn = _dateTimeUtil.GetCurrentDateTime(), Request = request, Response = new Exception("Test exception") }; // Act StaffResponse actual = _staffService.GetByManagerId(request, null).Result; // Assert Assert.AreEqual(expectedResponse, actual, "Response as expected"); _loggerMock.Verify(m => m.AddErrorLog(expectedLog), Times.Once); } [Test]
public IActionResult GetByManagerId([FromQuery] ByPersonIdRequest request) { try { StaffResponse response = _staffsClient.GetByManagerId(request); LogData logData = new() { CallSide = nameof(StaffController), CallerMethodName = nameof(GetByManagerId), CreatedOn = _dateTimeUtil.GetCurrentDateTime(), Request = request, Response = response }; _logger.AddLog(logData); return(Ok(response)); } catch (Exception ex) { LogData logData = new() { CallSide = nameof(StaffController), CallerMethodName = nameof(GetByManagerId), CreatedOn = _dateTimeUtil.GetCurrentDateTime(), Request = request, Response = ex }; _logger.AddErrorLog(logData); return(InternalServerError()); } } }
public static PersonInfo ToPersonInfo(this StaffResponse src) { if (src is null) { return(null); } var res = new PersonInfo() { Name = src.NameRu, ImageUrl = src.PosterUrl, Role = src.ProfessionText ?? string.Empty, Type = src.ProfessionKey.ToPersonType() }; if (string.IsNullOrWhiteSpace(res.Name)) { res.Name = src.NameEn ?? string.Empty; } if (src.AdditionalProperties.TryGetValue("description", out var description)) { res.Role = description as string; } res.SetProviderId(Constants.ProviderId, Convert.ToString(src.StaffId)); return(res); }
public StaffResponse Staffs([FromUri] StaffRequest request) { var result = new StaffResponse(); result.rows = GetData().Skip(request.start).Take(request.limit).Select(item => item).ToList(); result.total = result.rows.Count; result.success = true; return(result); }
public void GetAll_should_return_all_entities_from_db() { // Arrange StaffResponse expectedResponse = new() { Status = new BaseResponse { Code = Code.Success, ErrorMessage = string.Empty } }; Empty request = new(); expectedResponse.Data.Add(new StaffData { Id = _staff1.Id, CreatedOn = Timestamp.FromDateTime(_staff1.CreatedOn), ManagerId = _staff1.ManagerId, MotivationModificatorId = _staff1.MotivationModificatorId.GetValueOrDefault(), PersonId = _staff1.PersonId.GetValueOrDefault(), PositionId = _staff1.PositionId }); expectedResponse.Data.Add(new StaffData { Id = _staff2.Id, CreatedOn = Timestamp.FromDateTime(_staff2.CreatedOn), ManagerId = _staff2.ManagerId, MotivationModificatorId = _staff2.MotivationModificatorId.GetValueOrDefault(), PersonId = _staff2.PersonId.GetValueOrDefault(), PositionId = _staff2.PositionId }); LogData expectedLog = new() { CallSide = nameof(StaffService), CallerMethodName = nameof(_staffService.GetAll), CreatedOn = _dateTimeUtil.GetCurrentDateTime(), Request = request, Response = expectedResponse }; // Act StaffResponse actual = _staffService.GetAll(request, null).Result; // Assert Assert.AreEqual(expectedResponse, actual, "Response as expected"); _loggerMock.Verify(m => m.AddLog(expectedLog), Times.Once); } [Test]
public void GetByManagerId_should_return_response_from_grpc_client() { // Arrange ByPersonIdRequest request = new ByPersonIdRequest { PersonId = 1 }; StaffResponse response = new() { Status = new BaseResponse { Code = Code.Success, ErrorMessage = string.Empty } }; response.Data.Add(new StaffData { Id = 1, ManagerId = 1, PersonId = 2, CreatedOn = Timestamp.FromDateTime(_dateTimeUtil.GetCurrentDateTime()), MotivationModificatorId = 0, PositionId = 1 }); BaseMock.Response = response; LogData expectedLog = new() { CallSide = nameof(StaffController), CallerMethodName = nameof(_staffController.GetByManagerId), CreatedOn = _dateTimeUtil.GetCurrentDateTime(), Request = request, Response = response }; // Act ObjectResult actual = _staffController.GetByManagerId(request) as ObjectResult; StaffResponse actualData = actual.Value as StaffResponse; // Assert Assert.AreEqual(200, actual.StatusCode, "StatusCode as expected"); Assert.AreEqual(response, actualData, "Response data as expected"); _staffsClientMock.Verify(m => m.GetByManagerId(request, null, null, new CancellationToken()), Times.Once); _loggerMock.Verify(m => m.AddLog(expectedLog), Times.Once); } [Test]
public HttpResponseMessage Save(StaffRequest req) { StaffResponse res = new StaffResponse { Status = "OK" }; if (IsValid(req.SecurityToken)) { var studentSvc = new StaffService(this._dbContext); res.Staff = studentSvc.Save(req.Staff); } else { res = new StaffResponse { Status = "Error", ErrorCode = "ERR1001", ErrorMessage = "Invalid or expired token" }; CurrentLoggerProvider.Info(string.Format("Invalid Request. Student Id: {0}", req.Staff.StaffId)); } return(Request.CreateResponse(HttpStatusCode.OK, res)); }
public HttpResponseMessage GetCheckIn(HttpRequestMessage req) { string data = req.Content.ReadAsStringAsync().Result; string[] array = data.Split('&'); string[] userkeyValue = array[0].Split('='); string[] rolekeyValue = array[1].Split('='); string userid = userkeyValue[1]; string role = rolekeyValue[1]; try { if (userid != null && role != null) { if (role.ToUpper() == "MEMBER") { Member mem = mo.getMember(int.Parse(userid)); Contact con = co.GetContact(int.Parse(userid)); if (mem != null && mem.Id != null && mem.Id != 0) { Subscriptions sbs = sub.getSubscriptionByMemberID(mem.Id); MembershipOpt mo = new MembershipOpt(); if (sbs != null && sbs.Id != 0) { Membership mbr = mo.getMembershipByID(sbs.MembershipID); TimeSpan timeSpan = mbr.EndDate - DateTime.Now; TimeSpan timeSpan1 = mbr.StartDate - DateTime.Now; if (timeSpan1.Days > 0) { return(Request.CreateResponse(HttpStatusCode.OK, new Message("Membership Not Started"))); } else if (timeSpan.Days >= 0) { var url = req.RequestUri.GetLeftPart(UriPartial.Authority); MemberResponse mr = new MemberResponse(mem.Id, mem.FirstName + " " + mem.LastName, con.Cell, mbr.Name, mbr.StartDate.ToShortDateString(), mbr.EndDate.ToShortDateString(), url + mem.ImagePath, "Verified"); Visitor visit = new Visitor(); visit.UserID = int.Parse(mem.Id.ToString()); visit.UserType = "Member"; visit.VisitorName = mr.Name; visit.Date = DateTime.Today.ToShortDateString(); visit.Clock = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"); visit.Status = ""; vo.AddVisit(visit); return(Request.CreateResponse(HttpStatusCode.OK, mr)); } else { return(Request.CreateResponse(HttpStatusCode.OK, new Message("Membership Expired"))); } } else { return(Request.CreateResponse(HttpStatusCode.OK, new Message("Membership Not Found"))); } } else { return(Request.CreateResponse(HttpStatusCode.OK, new Message("Userid Not Found"))); } } else { Staff st = so.getStaffByID(userid); if (st != null) { var url = req.RequestUri.GetLeftPart(UriPartial.Authority); StaffResponse staff = new StaffResponse(st.FirstName + ' ' + st.LastName, st.Designation, st.Email, url + st.ImgURL, "Staff"); Visitor visit = new Visitor(); visit.UserID = int.Parse(st.StaffID.ToString()); visit.UserType = "Staff"; visit.VisitorName = staff.Name; visit.Date = DateTime.Today.ToShortDateString(); visit.Clock = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"); visit.Status = ""; vo.AddVisit(visit); return(Request.CreateResponse(HttpStatusCode.OK, staff)); } else { return(Request.CreateResponse(HttpStatusCode.OK, new Message("Staff Not Found"))); } } } else { return(Request.CreateResponse(HttpStatusCode.OK, new Message("Userid Required"))); } } catch (Exception e) { return(Request.CreateErrorResponse(HttpStatusCode.OK, "Please Contact to Server Adminstrator !!! ")); } }
public ResponseBase <StaffResponse> Login(RequestBase request) { var response = new ResponseBase <StaffResponse>(); var data = JsonConvert.DeserializeObject <StaffRequestDto>(request.data.ToString()); /// validate data request /// if (data == null || data.Username == null || data.Password == null) { response.message = "User or Password is Empty"; response.success = false; return(response); } //data.Password = Common.Md5Hash(data.Password); //data.Password = BCrypt.Net.BCrypt.HashPassword(data.Password); var staffHelperBo = new StaffHelperBo(); try { var login = staffHelperBo.GetUserByName(data); if (login.Username != null) { var isTrue = BCrypt.Net.BCrypt.Verify(data.Password, login.Password); if (isTrue) { response.message = "Login Success"; response.success = true; var dataReponse = new StaffResponse(); dataReponse.data = new System.Collections.Generic.List <StaffDataResponse>(); dataReponse.data.Add(new StaffDataResponse(login.ID, login.Name, login.Username, login.Password, login.CreatedDate)); response.data = dataReponse; return(response); } else { response.message = "Wrong User or Password"; response.success = false; return(response); } } else { response.message = "User or Password does not exist"; response.success = false; return(response); } } catch (Exception ex) { LogUtil.WriteError(this.ToString(), "Stack Trace: " + ex.StackTrace); LogUtil.WriteError(this.ToString(), "Message: " + ex.Message.ToString()); ErrorResponseBase errorResponse = new ErrorResponseBase(); errorResponse.errCode = ex.GetHashCode().ToString();; errorResponse.message = ex.Message.ToString(); response.success = false; response.message = "error"; response.error = errorResponse; } // return(response); }