public ActionResult _RequestHelp(HelpRequestModel model) { if (!ModelState.IsValid) { return(Json(new { success = false, message = ModelState.GetErrors() })); } const string subject = "CED Help Request"; var recipient = WebConfigHelper.AdminEmails; // WebConfigHelper.HelpDeskUserName; var actorUserEmail = CurrentCedUser.CurrentUser.Email; var body = model.Message + "<p><b>Sender:</b> " + actorUserEmail + "</p>"; try { EmailHelper.SendEmail(subject, body, recipient); // EMAIL LOGGING LogEmail(null, recipient, body, actorUserEmail, "_RequestHelp"); return(Json(new { success = true })); } catch (Exception exc) { var log = CreateInternalLog(exc); ExternalLogHelper.Log(log, LoggingEventType.Error); return(Json(new { success = false, message = exc.Message })); } }
/// <summary> /// Create a new help request for a specific help seeker if the id is 0. /// Else if a help request already exists with the same id, the existing help request will be updated. /// </summary> /// <param name="helpRequest"> /// The new or updated help request. /// </param> /// <returns> /// The created or updated help request. /// </returns> public HelpRequestModel Save(HelpRequestModel helpRequest) { //Default location GeoCoordinate location = new GeoCoordinate(52.132633, 5.291265999999999); string address = "Nederland"; //Try to get location if (helpRequest.Address != address) { GoogleMapsApi.Response googleMapsApi = GoogleMapsApi.Get(helpRequest.Address, "nl", "nl"); if (googleMapsApi != null) { location = googleMapsApi.Location; address = googleMapsApi.Address; } } helpRequest.Location = location; helpRequest.Address = address; if (helpRequest.Id == 0) { helpRequest.Id = context.Create(helpRequest); Console.WriteLine(helpRequest.Id + helpRequest.Title); } else { context.Update(helpRequest); } return(helpRequest); }
public HelpRequestCommentsModel(User user, HelpRequestModel helpRequest) { Creator = user; HelpRequestModel = helpRequest; if (Creator.Username == LocalUserManager.LocalUser.Username) { DeleteButtonText = "Ištrinti"; } }
public void Update(HelpRequestModel updatedHelpRequest) { var results = from helpRequest in Tables.HelpRequest where helpRequest.Id == updatedHelpRequest.Id && helpRequest.HelpSeeker.Id == updatedHelpRequest.HelpSeeker.Id select helpRequest; if (results.Count() == 1) { HelpRequestModel result = results.ElementAt(0); result.Title = updatedHelpRequest.Title; result.Content = updatedHelpRequest.Content; result.Address = updatedHelpRequest.Address; result.Urgency = updatedHelpRequest.Urgency; } }
public void _RequestHelp_Invalid_ReturnsJsonRequest() { // Arrange var model = new HelpRequestModel(); _sut.EmailHelper = new Mock <IEmailHelper>().Object; // Act var result = _sut._RequestHelp(model); // Assert Assert.IsInstanceOfType(result, typeof(JsonResult)); var jsonResult = (JsonResult)result; Assert.AreEqual(true, jsonResult.GetValue <bool>("success")); }
public ChatModel Get(int chatId) { ChatModel chat = null; var results = from message in Tables.Message where message.Chat.Id == chatId join application in Tables.Application on message.Chat.Id equals application.Id join helpRequest in Tables.HelpRequest on application.HelpRequest.Id equals helpRequest.Id orderby message.Date descending select new { Message = message, Application = application, HelpRequest = helpRequest }; foreach (object result in results) { //http://stackoverflow.com/a/3358389 Type type = result.GetType(); MessageModel message = (MessageModel)type.GetProperty("Message").GetValue(result, null); ApplicationModel application = (ApplicationModel)type.GetProperty("Application").GetValue(result, null); HelpRequestModel helpRequest = (HelpRequestModel)type.GetProperty("HelpRequest").GetValue(result, null); if (chat == null) { chat = (new ChatModel { Id = application.Id, Title = helpRequest.Title, Status = application.Status, Messages = new List <MessageModel>() }); } chat.Messages.Add(new MessageModel { Id = message.Id, User = new UserModel { Id = message.User.Id }, Chat = new ChatModel { Id = application.Id }, Content = message.Content, Date = message.Date }); } return(chat); }
public int Create(HelpRequestModel helpRequest) { int id = Tables.HelpRequest.Count() > 0 ? Tables.HelpRequest.Max(x => x.Id) + 1 : 1; Tables.HelpRequest.Add(new HelpRequestModel { Id = id, Title = helpRequest.Title, Address = helpRequest.Address, Location = helpRequest.Location, Content = helpRequest.Content, Date = DateTime.Now, Closed = false, Urgency = helpRequest.Urgency, HelpSeeker = helpRequest.HelpSeeker }); return(helpRequest.Id); }
public async void Get_Help() { var helpRequestModel = new HelpRequestModel() { Client = new Client() { Url = "https://msmatter.sharepoint.com/sites/catalog" }, SelectedPage = "" }; using (var client = testServer.CreateClient().AcceptJson()) { var response = await client.PostAsJsonAsync("http://localhost:44323/api/v1/shared/help", helpRequestModel); var result = response.Content.ReadAsJsonAsync <List <ContextHelpData> >().Result; Assert.NotNull(result); } }
public void Update(HelpRequestModel helpRequest) { string query = @"UPDATE [HelpRequest] SET Title = @Title, Content = @Content, Address = @Address, Location = geography::STPointFromText(@Location, 4326), Urgency = @Urgency WHERE Id = @Id AND HelpSeekerUserId = @HelpSeekerUserId"; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) using (SqlCommand cmd = new SqlCommand(query, conn)) { conn.Open(); cmd.Parameters.AddWithValue("@Id", helpRequest.Id); cmd.Parameters.AddWithValue("@HelpSeekerUserId", helpRequest.HelpSeeker.Id); cmd.Parameters.AddWithValue("@Title", helpRequest.Title); cmd.Parameters.AddWithValue("@Content", helpRequest.Content); cmd.Parameters.AddWithValue("@Address", helpRequest.Address); cmd.Parameters.AddWithValue("@Location", "POINT(" + helpRequest.Location.Longitude + " " + helpRequest.Location.Latitude + ")"); cmd.Parameters.AddWithValue("@Urgency", (int)helpRequest.Urgency); cmd.ExecuteNonQuery(); } }
public int Create(HelpRequestModel helpRequest) { int id; string query = @"INSERT INTO [HelpRequest] (HelpSeekerUserId, Title, Content, Date, Address, Location, Urgency, Closed) VALUES (@HelpSeekerUserId, @Title, @Content, GETDATE(), @Address, geography::STPointFromText(@Location, 4326), @Urgency, 0); SELECT SCOPE_IDENTITY();"; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) using (SqlCommand cmd = new SqlCommand(query, conn)) { conn.Open(); cmd.Parameters.AddWithValue("@HelpSeekerUserId", helpRequest.HelpSeeker.Id); cmd.Parameters.AddWithValue("@Title", helpRequest.Title); cmd.Parameters.AddWithValue("@Content", helpRequest.Content); cmd.Parameters.AddWithValue("@Address", helpRequest.Address); cmd.Parameters.AddWithValue("@Location", "POINT(" + helpRequest.Location.Longitude + " " + helpRequest.Location.Latitude + ")"); cmd.Parameters.AddWithValue("@Urgency", (int)helpRequest.Urgency); id = Convert.ToInt32(cmd.ExecuteScalar()); } return(id); }
public HelpRequestModel Get(int id) { HelpRequestModel result = null; string query = @"SELECT [HelpRequest].HelpSeekerUserId, [User].Name, [HelpRequest].Title, [HelpRequest].Content, [HelpRequest].Date, [HelpRequest].Address, [HelpRequest].Urgency, [HelpRequest].Closed FROM [HelpRequest] JOIN [User] ON [HelpRequest].HelpSeekerUserId = [User].Id WHERE [HelpRequest].Id = @Id"; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString)) using (SqlCommand cmd = new SqlCommand(query, conn)) { conn.Open(); cmd.Parameters.AddWithValue("@Id", id); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { result = new HelpRequestModel { Id = id, HelpSeeker = new UserModel { Id = reader.GetInt32(0), Name = reader.GetString(1) }, Title = reader.GetString(2), Content = reader.GetString(3), Date = reader.GetDateTime(4), Address = reader.GetString(5), Urgency = (HelpRequestUrgency)reader.GetInt32(6), Closed = reader.GetBoolean(7) }; } } } return(result); }
public async Task <IActionResult> Help([FromBody] HelpRequestModel helpRequestModel) { string selectedPage = helpRequestModel.SelectedPage; Client client = helpRequestModel.Client; string result = string.Empty; try { #region Error Checking ErrorResponse errorResponse = null; if (client == null && string.IsNullOrWhiteSpace(selectedPage)) { errorResponse = new ErrorResponse() { Message = errorSettings.MessageNoInputs, ErrorCode = HttpStatusCode.BadRequest.ToString(), Description = "No input data is passed" }; return(matterCenterServiceFunctions.ServiceResponse(errorResponse, (int)HttpStatusCode.NotFound)); } #endregion List <ContextHelpData> contextHelpCollection = new List <ContextHelpData>(); string[] pageNames = sharedSettings.MatterCenterPages.Split(';'); switch (selectedPage) { case "1": selectedPage = pageNames[1]; break; case "2": selectedPage = pageNames[2]; break; case "4": selectedPage = pageNames[4]; break; default: selectedPage = pageNames[0]; break; } string cacheKey = string.Concat(selectedPage, ServiceConstants.LINKS_STATIC_STRING); result = ServiceUtility.GetDataFromAzureRedisCache(cacheKey); if (string.IsNullOrEmpty(result)) { contextHelpCollection = await sharedRepository.GetMatterHelpAsync(client, selectedPage); ServiceUtility.SetDataIntoAzureRedisCache <List <ContextHelpData> >(cacheKey, contextHelpCollection); } else { contextHelpCollection = JsonConvert.DeserializeObject <List <ContextHelpData> >(result); } return(matterCenterServiceFunctions.ServiceResponse(contextHelpCollection, (int)HttpStatusCode.OK)); } catch (Exception exception) { customLogger.LogError(exception, MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name, logTables.SPOLogTable); throw; } }