public Response CreateBlogPost(int blogId, string title, string content)
        {
            var response = new Response{ IsError = false, Message = string.Format("Post successfully added to blog id {0}!", blogId)};

            var blogToUpdate = _Repository.GetAll("Posts")
                .FirstOrDefault(blog => blog.BlogId == blogId);

            //Return an error if the blog is null
            if (blogToUpdate == null)
            {
                response.IsError = true;
                response.Message = string.Format("Blog id {0} not found.", blogId);
                return response;
            }

            try
            {
                blogToUpdate.Posts.Add(new Post{Title = title, Content = content});
                _Repository.SubmitChanges();
            }
            catch (Exception ex)
            {
                response.IsError = true;
                response.Message = string.Format("An error occured while trying update blog id {0}", blogId);
            }

            return response;
        }
예제 #2
0
 private static void DisplayResult(Response result)
 {
     ColorConsole.WriteInColor(result.ToString(), result.Succeeded ? ConsoleColor.Green : ConsoleColor.Red);
 }
예제 #3
0
		void UsbRunner_NewResponse(Device usbDevice, Response response)
		{
			try
			{
				if (USBDevice.UID == usbDevice.UID)
				{
					//Trace.WriteLine("response.Id=" + response.Id);
					foreach (var monitoringPanel in MonitoringPanels)
					{
						if (monitoringPanel.Requests.Count > 0)
							for (int i = 0; i < monitoringPanel.Requests.Count; i++)
							{
								var request = monitoringPanel.Requests[i];
								if (request != null && response.Id != 0 && request.Id == response.Id)
								{
									var idOffset = 0;
									if (response.Id > 0)
										idOffset = 4;
									for (int j = 0; j < request.RootBytes.Count; j++)
									{
										if (request.RootBytes[j] != response.Bytes[idOffset + j])
										{
											Trace.WriteLine("В пришедшем ответе совпадают ID, но не совпадают маршруты");
											return;
										}
									}
									monitoringPanel.OnResponceRecieved(request, response);
								}
							}
					}
				}
			}
			catch (Exception e)
			{
				Logger.Error(e, "MonitoringUSB.UsbRunner_NewResponse");
			}
		}