// アプリケーションの開始イベント void App_Startup(object sender, StartupEventArgs e) { List<CsvTest> list = new List<CsvTest>(); list.Add(new CsvTest("テスト\r\n文\"字1", 1111, 12.006, DateTime.Now)); list.Add(new CsvTest("テスト文字2", 1112, 13.006, DateTime.Today)); list.Add(new CsvTest("テスト文字3", 1113, 14.006, DateTime.MinValue)); ContractUtil DataUtil = new ContractUtil(); bool ret1 = DataUtil.Compare(list[0], list[1]); bool ret2 = DataUtil.Compare(list[2], list[2]); CsvUtil csv = new CsvUtil(Encoding.UTF8, true); // csv.Write(list, @"D:\\momiji\\sample.csv"); // List<CsvTest> list2 = csv.Read<CsvTest>(@"D:\\momiji\\sample.csv"); List<CsvTest> list2 = csv.Read<CsvTest>(null); // 例外ハンドラの登録 this.DispatcherUnhandledException += App_DispatcherUnhandledException; AppDomain.CurrentDomain.UnhandledException += App_UnhandledException; // アプリケーションの初期化 ContextModel.loginInfo.ShainInfo.SHAIN_CD = "000001"; SystemEnviroment.Init(); // ウィンドウの表示 Window window = GetPlugin.Load("Window1"); window.Show(); }
public async Task <JsonResult> Delete(int id) { var response = await Task.Run(() => { var productsResponse = _productService.RemoveProduct(ContractUtil.CreateRequest(new GetProductRequest { Id = id })); return(Json(productsResponse)); }); return(response); }
public IEnumerable <Notification> GetNotifications(User user) { ContractUtil.NotNull(user); foreach (var notification in _unitOfWork.Notifications.FindNotificationsFor(user) .Where(notification => !notification.IsRead)) { notification.IsRead = true; //_unitOfWork.Commit(); yield return(notification); } }
/// <summary> /// Adds a new user to the current repository. /// </summary> /// <param name="user">The new user to add.</param> public void Add(User user) { ContractUtil.NotNull(user); ContractUtil.IsDefault(user.Id); var keyword = Container.Instance.Resolve <IKeyGenerationService>().CreateKey(user); // TODO: Maybe inject dependency through the constructor user.Keyword = keyword; var key = GetNewKey(); user.Id = key; _data.Add(key, user); }
/// <summary> /// Retrieve the posts that will be show to a given user. /// </summary> /// <param name="user">An user.</param> /// <param name="page">The page number.</param> /// <param name="count">The posts count.</param> /// <returns></returns> public IList <Post> GetPosts(User user, int page = 1, int count = 10) { ContractUtil.NotNull(user); ContractUtil.IsInRange(page, 1); ContractUtil.IsInRange(count, 1); var postRepository = _unitOfWork.Posts; return(user.Friends.SelectMany(postRepository.FindPostsTo) .Where(post => post.IsPersonal) .Concat(postRepository.FindPostsTo(user)) .OrderByDescending(post => post.Date) .Paginate(page, count) .ToList()); }
public ContractResponse <GetProductResponse> UpdateProduct(ContractRequest <AddUpdateProductRequest> request) { ContractResponse <GetProductResponse> response; try { var model = request.Data.Product.ToProduct(); var brokenRules = model.GetBrokenRules().ToList(); if (brokenRules.Any()) { var message = new GetProductResponse { Product = request.Data.Product, }; response = ContractUtil.CreateInvalidResponse <GetProductResponse>(brokenRules, message); } else { var oldProduct = _productRepository.FindById(request.Data.Product.Id); if (string.IsNullOrEmpty(request?.Data?.Product?.Image)) { model.Image = oldProduct.Image; } _productRepository.Update(model); var product = model.ToProductView(); var message = new GetProductResponse { Product = product }; response = ContractUtil.CreateResponse <GetProductResponse, AddUpdateProductRequest>(request, message); } } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); return(ContractUtil.CreateInvalidResponse <GetProductResponse>(ex)); } return(response); }
public ContractResponse <UserGetResponse> GetUser(ContractRequest <UserGetRequest> request) { User user; if (string.IsNullOrEmpty(request.Data.UserName)) { user = _userRepository.First(u => u.Id == request.Data.Id); } else { user = _userRepository.First(u => u.UserName.Equals(request.Data.UserName, StringComparison.InvariantCultureIgnoreCase)); } return(ContractUtil.CreateResponse(request, new UserGetResponse { User = user?.ToUserView() })); }
public ContractResponse <GetProductResponse> UpdateProduct(ContractRequest <AddUpdateProductRequest> request) { ContractResponse <GetProductResponse> response; try { var requestService = CreateRequest(request, $"products/{request.Data.Product.Id}", Method.PUT); var responseService = _client.Execute <ContractResponse <GetProductResponse> >(requestService); response = responseService.Data; } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); response = ContractUtil.CreateInvalidResponse <GetProductResponse>(ex); } return(response); }
public ContractResponse <GetProductResponse> AddProduct(ContractRequest <AddUpdateProductRequest> request) { ContractResponse <GetProductResponse> response; try { var model = request.Data.Product.ToProduct(); var brokenRules = model.GetBrokenRules().ToList(); if (brokenRules.Any()) { var message = new GetProductResponse { Product = request.Data.Product, }; response = ContractUtil.CreateInvalidResponse <GetProductResponse>(brokenRules, message); } else { _productRepository.Add(model); var product = model.ToProductView(); var message = new GetProductResponse { Product = product }; response = ContractUtil.CreateResponse <GetProductResponse, AddUpdateProductRequest>(request, message); } } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); return(ContractUtil.CreateInvalidResponse <GetProductResponse>(ex)); } return(response); }
public async Task <ContractResponse <GetAllProductsResponse> > GetAllProducts(ContractRequest <BaseRequest> request) { ContractResponse <GetAllProductsResponse> response; try { var requestService = CreateRequest(request, "products", Method.GET); var responseService = await _client.ExecuteGetTaskAsync <ContractResponse <GetAllProductsResponse> >(requestService); response = responseService.Data; } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); response = ContractUtil.CreateInvalidResponse <GetAllProductsResponse>(ex); } return(response); }
public ContractResponse <PatientListGetResponse> Get(ContractRequest <PatientGetRequest> request) { ContractResponse <PatientListGetResponse> response; try { var model = _patientRepository.FindBy(e => e.Id == request.Data.Id); var modelListResponse = model.ToPatientViewList(); response = ContractUtil.CreateResponse(request, new PatientListGetResponse { Patients = modelListResponse.ToList() }); } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); response = ContractUtil.CreateInvalidResponse <PatientListGetResponse>(ex); } return(response); }
public ContractResponse <AppointmentListGetResponse> GetAll(ContractRequest <BaseRequest> request) { ContractResponse <AppointmentListGetResponse> response; try { var modelList = _appointmentRepository.GetAll(); var modelListResponse = modelList.ToAppointmentViewList(); response = ContractUtil.CreateResponse(request, new AppointmentListGetResponse { Appointments = modelListResponse.ToList() }); } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); response = ContractUtil.CreateInvalidResponse <AppointmentListGetResponse>(ex); } return(response); }
public ContractResponse <GetProductResponse> GetProduct(ContractRequest <GetProductRequest> request) { ContractResponse <GetProductResponse> response; try { var model = _productRepository.FindById(request.Data.Id); var modelResponse = model?.ToProductView(); response = ContractUtil.CreateResponse(request, new GetProductResponse { Product = modelResponse }); } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); response = ContractUtil.CreateInvalidResponse <GetProductResponse>(ex); } return(response); }
public ContractResponse <GetAllProductsResponse> GetAllProducts(ContractRequest <BaseRequest> request) { ContractResponse <GetAllProductsResponse> response; try { var userList = _productRepository.FindAll(); var modelResponse = userList.ToProductViewList(); response = ContractUtil.CreateResponse(request, new GetAllProductsResponse { Products = modelResponse }); } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); response = ContractUtil.CreateInvalidResponse <GetAllProductsResponse>(ex); } return(response); }
public ContractResponse <BaseResponse> RemoveProduct(ContractRequest <GetProductRequest> request) { ContractResponse <BaseResponse> response; try { var model = new Product { Id = request.Data.Id }; _productRepository.Remove(model); response = ContractUtil.CreateResponse(request, new BaseResponse()); } catch (Exception ex) { _logger.LogError(20, ex, ex.Message); response = ContractUtil.CreateInvalidResponse <BaseResponse>(ex); } return(response); }
public FriendshipStatus GetFriendshipStatus(User current, User other) { ContractUtil.NotNull(current); ContractUtil.NotNull(other); if (current.Equals(other)) { throw new Exception(); } if (current.Friends.Contains(other)) { return(FriendshipStatus.AlreadyFriends); } if (_unitOfWork.FriendshipRequests.FindSentTo(other).Any(request => request.Sender.Id.Equals(current.Id))) { return(FriendshipStatus.RequestSentByYou); } if (_unitOfWork.FriendshipRequests.FindSentFrom(other).Any(request => request.Reciver.Id.Equals(current.Id))) { return(FriendshipStatus.RequestSentByOther); } return(FriendshipStatus.NoRelation); }
/// <summary> /// Send a friendship request from an user to another one. /// </summary> /// <param name="sender">The user that sends the request.</param> /// <param name="reciver">The user that receives the request.</param> public void SendRequest(User sender, User reciver) { ContractUtil.NotNull(sender); ContractUtil.NotNull(reciver); var requestRepository = _unitOfWork.FriendshipRequests; // Checking that the request isn't already sent ... if (requestRepository.FindSentFrom(sender).Any(request => reciver.Id.Equals(request.Reciver.Id))) { return; } var notificationRepository = _unitOfWork.Notifications; var newRequest = new FriendshipRequest(sender, reciver, _dateTimeService.Now()); var newNotification = _notificationFactory.CreateFriendshipRequest(sender, reciver); requestRepository.Add(newRequest); notificationRepository.Add(newNotification); _unitOfWork.Commit(); }
public User FindByKeyword(string keyword) { ContractUtil.NotNull(keyword); return(Set.SingleOrDefault(account => keyword.Equals(account.Keyword))); }
/// <summary> /// Retrieve the posts that were posted to a given account: <paramref name="owner"/> /// </summary> /// <param name="owner">An account.</param> /// <returns>The posts that were poetd to <paramref name="owner"/></returns> public IQueryable <Post> FindPostsTo(User owner) { ContractUtil.NotNull(owner); return(Set.Where(post => post.Owner.Id.Equals(owner.Id))); }
/// <summary> /// Retrieve the messages that are sent to a given account: <paramref name="account"/> /// </summary> /// <param name="account">An account.</param> /// <returns>The messages that are sent by <paramref name="account"/></returns> public IQueryable <Message> FindMessagesTo(User account) { ContractUtil.NotNull(account); return(_data.Values.Where(message => account.Equals(message.Reciver)).AsQueryable()); }
/// <summary> /// Adds a post to the current repository. /// </summary> /// <param name="post">The post to add.</param> public void Add(Post post) { ContractUtil.NotNull(post); Set.Add(post); }
public void Update(Business.Domain.Users.User user) { ContractUtil.NotNull(user); if (Image != null) { var format = Path.GetExtension(Image.FileName); var data = new byte[Image.InputStream.Length]; Image.InputStream.Read(data, 0, data.Length); var img = new Image(data, format, ""); user.SetPhoto(img); } if (State != user.Profile.ContactInformation.Address.State) { user.Profile.ContactInformation.Address.State = State; } if (AboutMe != user.Profile.PersonalInformation.AboutMe) { user.Profile.PersonalInformation.AboutMe = AboutMe; } if (City != user.Profile.ContactInformation.Address.City) { user.Profile.ContactInformation.Address.City = City; } if (BirthDay != user.Profile.PersonalInformation.BirthDay) { user.Profile.PersonalInformation.BirthDay = BirthDay; } if (HomeTown != user.Profile.PersonalInformation.HomeTown) { user.Profile.PersonalInformation.HomeTown = HomeTown; } if (EMail != user.Profile.ContactInformation.EMail) { user.Profile.ContactInformation.EMail = EMail; } if (EMailOnlyForFriends != user.Profile.ContactInformation.EMailOnlyForFriends) { user.Profile.ContactInformation.EMailOnlyForFriends = EMailOnlyForFriends; } if (Country != user.Profile.ContactInformation.Address.Country) { user.Profile.ContactInformation.Address.Country = Country; } if (AddressInfo != user.Profile.ContactInformation.Address.AddressInfo) { user.Profile.ContactInformation.Address.AddressInfo = AddressInfo; } if (AddressOnlyForFriends != user.Profile.ContactInformation.AddressOnlyForFriends) { user.Profile.ContactInformation.AddressOnlyForFriends = AddressOnlyForFriends; } if (InterestedInMen != user.Profile.PersonalInformation.InterestedInMen) { user.Profile.PersonalInformation.InterestedInMen = InterestedInMen; } if (InterestedInWomen != user.Profile.PersonalInformation.InterestedInWomen) { user.Profile.PersonalInformation.InterestedInWomen = InterestedInWomen; } if (LookingForFriendship != user.Profile.PersonalInformation.LookingForFriendship) { user.Profile.PersonalInformation.LookingForFriendship = LookingForFriendship; } if (LookingForRelationship != user.Profile.PersonalInformation.LookingForRelationship) { user.Profile.PersonalInformation.LookingForRelationship = LookingForRelationship; } if (MobileNumber != user.Profile.ContactInformation.MobileNumber) { user.Profile.ContactInformation.MobileNumber = MobileNumber; } if (MobileNumberOnlyForFriends != user.Profile.ContactInformation.MobileNumberOnlyForFriends) { user.Profile.ContactInformation.MobileNumberOnlyForFriends = MobileNumberOnlyForFriends; } }
/// <summary> /// Retrieve the posts that were posted by a given account: <paramref name="author"/> /// </summary> /// <param name="author">An account.</param> /// <returns>The posts that were posted by <paramref name="author"/></returns> public IQueryable <Post> FindPostsFrom(User author) { ContractUtil.NotNull(author); return(_data.Values.Where(message => author.Equals(message.Author)).AsQueryable()); }
/// <summary> /// Retrieve the posts that were posted to a given account: <paramref name="owner"/> /// </summary> /// <param name="owner">An account.</param> /// <returns>The posts that were poetd to <paramref name="owner"/></returns> public IQueryable <Post> FindPostsTo(User owner) { ContractUtil.NotNull(owner); return(_data.Values.Where(post => owner.Equals(post.Owner)).AsQueryable()); }
public IEnumerable <Message> GetMessages(User user) { ContractUtil.NotNull(user); return(_unitOfWork.Messages.FindMessagesTo(user).OrderByDescending(message => message.Date)); }
/// <summary> /// Retrieve the posts that were posted by a given account: <paramref name="author"/> /// </summary> /// <param name="author">An account.</param> /// <returns>The posts that were posted by <paramref name="author"/></returns> public IQueryable <Post> FindPostsFrom(User author) { ContractUtil.NotNull(author); return(Set.Where(post => post.Author.Id.Equals(author.Id))); }
/// <summary> /// Retrieve the user with the given email. /// </summary> /// <param name="email">The email of the user.</param> /// <returns></returns> public User FindByEmail(string email) { ContractUtil.NotNull(email); return(_data.Values.SingleOrDefault(account => Equals(account.EMail, email))); }
public void Add(Image img) { ContractUtil.NotNull(img); Set.Add(img); }
/// <summary> /// Retrieve all requests that are sent to a given user. /// </summary> /// <param name="user">Reciver</param> /// <returns>All the friendship request that <paramref name="user"/> had receive.</returns> public IQueryable <FriendshipRequest> FindSentTo(User user) { ContractUtil.NotNull(user); return(_data.Values.AsQueryable().Where(request => user.Equals(request.Reciver))); }
/// <summary> /// Retrieve all requests that are sent to a given user. /// </summary> /// <param name="user">Reciver</param> /// <param name="spec">An optional aditional specification. </param> /// <returns>All the friendship request that <paramref name="user"/> had receive.</returns> public IQueryable <FriendshipRequest> FindSentTo(User user) { ContractUtil.NotNull(user); return(Set.Where(request => request.Reciver.Id.Equals(user.Id))); }
/// <summary> /// Retrieve the user with the given email. /// </summary> /// <param name="email">The email of the user.</param> /// <returns></returns> public User FindByEmail(string email) { ContractUtil.NotNull(email); return(Set.SingleOrDefault(account => email.Equals(account.EMail))); }