public void HandleEvent(EntityCreatedEventData <Task> eventData) { _activityService.AddActivity( new CreateTaskActivity { CreatorUser = eventData.Entity.CreatorUserId.HasValue ? _userRepository.Load(eventData.Entity.CreatorUserId.Value) : null, AssignedUser = eventData.Entity.AssignedUser, Task = eventData.Entity }); }
public void AddCommentNotificationsAndActivity(long?parentId, long contentId, long subDirectoryId, User creator) { if (parentId.HasValue) { var parentComment = GetCommentById(parentId.Value); _notificationService.AddNotification(NotificationTypeMap.Reply, parentComment.ContentId, parentComment.CreatorId, subDirectoryId, creator.Fullname); _activityService.AddActivity(ActivityTypeMap.Replied, contentId, creator.Id, subDirectoryId); } else { _activityService.AddActivity(ActivityTypeMap.Commented, contentId, creator.Id, subDirectoryId); } }
public ActionResult <ActivityAddResViewModel> Manage_OpinionInfo_Add(ActivityAddViewModel activityAddViewModel) { activityAddViewModel.Id = Guid.NewGuid(); int Activity_add_Count; Activity_add_Count = _activityService.AddActivity(activityAddViewModel); var opinionInfoAddResModel = _activityFactory.GetActivityAddResViewModel(); //添加附件中的FormId foreach (FileUpload fileUpload in activityAddViewModel.Files) { fileUpload.FormId = activityAddViewModel.Id; _activityUploadService.UpdateFile(fileUpload); } if (Activity_add_Count > 0) { opinionInfoAddResModel.baseViewModel.IsSuccess = true; opinionInfoAddResModel.AddCount = Activity_add_Count; opinionInfoAddResModel.baseViewModel.Message = "添加成功"; opinionInfoAddResModel.baseViewModel.ResponseCode = 200; _ILogger.Information("增添活动信息成功"); return(Ok(opinionInfoAddResModel)); } else { opinionInfoAddResModel.baseViewModel.IsSuccess = false; opinionInfoAddResModel.AddCount = 0; opinionInfoAddResModel.baseViewModel.Message = "添加失败"; opinionInfoAddResModel.baseViewModel.ResponseCode = 400; _ILogger.Information("增添活动信息失败"); return(BadRequest(opinionInfoAddResModel)); } }
public bool RunValidationForUser(long userId, long contentId, bool shouldBePersisted) { var contentToPersist = _contentService.GetContentById(contentId); var userValidationExists = _userContentValidationService.HasUserValidatedAlready(userId, contentId); var systemValues = _systemValuesService.GetNewestSystemValue(); if (systemValues != null && contentToPersist != null && !userValidationExists) { var persistCount = _userContentValidationService.GetValidationsForContent(contentId, true) .Count(); if (contentToPersist.AppliedForPersistence == true && contentToPersist.EligableForPersistanceAt != null && persistCount < systemValues.ValidationUserMaxCount && !contentToPersist.ReferredViaValidationToAdmin) { var validated = _userContentValidationService.AddValidationRecord(userId, contentId, shouldBePersisted); if (validated) { _activityService.AddActivity(ActivityTypeMap.ValidatedContent, contentId, userId, contentToPersist.SubDirectoryId); if (persistCount >= systemValues.ValidationUserMaxCount) { EndValidationEvent(userId, contentId, systemValues.ValidationUserThresholdPercent, systemValues.ValidationUserMaxRunCount, systemValues.AmountToPayForUserValidation); } return(true); } } } return(false); }
public HttpResponseMessage AddActivity(HttpRequestMessage request, [FromBody] Activity activity) { return(Execute(request, () => { bool completed = _activityService.AddActivity(activity); return request.CreateResponse(completed); })); }
public ActionResult Add() { if (Request.Form != null && Request.Form.Count > 0) { ResponseStatus resp = activityService.AddActivity(Request); return(this.JudgeResult(resp, () => RedirectToAction("Details", new { msg = string.Format("添加了活动:{0}", Request.Form["content"]) }))); } return(View()); }
public void Handle(BranchAddCommand command) { using (var uow = new UnitOfWork <EF>()) { try { var branchEntity = new Branch() { BranchId = Guid.NewGuid().ToString(), Name = command.Branch.Name, Address = command.Branch.Address, BranchCode = command.Branch.BranchCode, Email = command.Branch.Email, Phone = command.Branch.Phone, Description = command.Branch.Description, CreatedDate = System.DateTime.Now, LastModifiedDate = System.DateTime.Now }; uow.Repository <Branch>().Add(branchEntity); uow.SubmitChanges(); //Insert new Activity var activity = new Activity() { Source = "Chi nhánh", Source_Id = branchEntity.BranchId, Action = "Tạo", Current_value = branchEntity.Name, CreatedDate = System.DateTime.Now, CreatedBy = command.Branch.UserId }; iActivityServices.AddActivity(new ActivityAddCommand { Activity = activity }); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception) { throw; } } }
public async Task <IActionResult> Create(ActivityCreateViewModel form) { if (ModelState.IsValid) { var m = new Activity { Name = form.Name, Date = form.Date, Code = form.Code }; var activities = _activityService.GetActivitiesAsync(out int _); if (activities.Result.Any()) { m.Code = activities.Result.Last().Code + 1; } else { m.Code = 1; } TryValidateModel(m); if (!ModelState.IsValid) { return(Json(new { success = "fail", errorList = JsonConvert.SerializeObject(ModelState.Values.Where(x => x.Errors.Count > 0), Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }) })); } if (_optionsAccessor.Value.EfSettings.DataContext.SaveEntity) { _activityService.AddActivity(m, out var result); if (result > 0) { if (_optionsAccessor.Value.EfSettings.DataContext.SendEmail) { await SendCreatedConfirmEmail(m); } _cache.Remove(Url.Action("GetActivities", "Activity")); return(Content("success")); } } } return(Json(new { success = "fail", errorList = JsonConvert.SerializeObject(ModelState.Values.Where(x => x.Errors.Count > 0), Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }) })); }
public void Handle(MerchandiseTypeAddCommand command) { using (var uow = new UnitOfWork <EF>()) { try { //add var merchandiseTypeEntity = new MerchandiseType() { MerchandiseId = Guid.NewGuid().ToString(), Type = command.MerchandiseType.Type, Name = command.MerchandiseType.Name, CalculationUnit = command.MerchandiseType.CalculationUnit, Description = command.MerchandiseType.Description, CreatedDate = System.DateTime.Now, LastModifiedDate = System.DateTime.Now }; uow.Repository <MerchandiseType>().Add(merchandiseTypeEntity); uow.SubmitChanges(); //Insert new Activity var activity = new Activity(); activity.Source = "Loại Hàng"; activity.Source_Id = merchandiseTypeEntity.MerchandiseId; activity.Action = "Tạo"; activity.Current_value = merchandiseTypeEntity.Name; activity.CreatedDate = System.DateTime.Now; activity.CreatedBy = command.MerchandiseType.UserId; iActivityServices.AddActivity(new ActivityAddCommand { Activity = activity }); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception) { throw; } } }
public void Handle(DeliveryTypeAddCommand command) { using (var uow = new UnitOfWork <EF>()) { try { var deliveryTypeEntity = new DeliveryType() { DeliveryId = Guid.NewGuid().ToString(), Name = command.DeliveryType.Name, Value = command.DeliveryType.Value, Description = command.DeliveryType.Description, CreatedDate = System.DateTime.Now, LastModifiedDate = System.DateTime.Now }; uow.Repository <DeliveryType>().Add(deliveryTypeEntity); uow.SubmitChanges(); //Insert new Activity var activity = new Activity() { Source = "Giao nhận", Source_Id = deliveryTypeEntity.DeliveryId, Action = "Tạo", Current_value = deliveryTypeEntity.Name, CreatedDate = System.DateTime.Now, CreatedBy = command.DeliveryType.UserId }; iActivityServices.AddActivity(new ActivityAddCommand { Activity = activity }); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception) { throw; } } }
public void Handle(BranchAddressUpdateCommand command) { using (var uow = new UnitOfWork <EF>()) { try { //update var branchEntity = uow.Repository <Branch>().GetById(p => p.BranchId.Equals(command.BranchId) && !p.DeletedDate.HasValue); var previousVal = branchEntity.Address; branchEntity.LastModifiedDate = System.DateTime.Now; branchEntity.Address = command.Address; uow.Repository <Branch>().Update(branchEntity); uow.SubmitChanges(); //log //Inset new Activity var activity = new Activity() { Source = "Chi nhánh", Source_Id = branchEntity.BranchId, Action = "Sửa", Previous_value = previousVal, Current_value = command.Address, CreatedDate = System.DateTime.Now, CreatedBy = command.UserId }; iActivityServices.AddActivity(new ActivityAddCommand { Activity = activity }); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception) { throw; } } }
public void Handle(DeliveryTypeActiveUpdateCommand command) { using (var uow = new UnitOfWork <EF>()) { try { //update var deliveryTypeEntity = uow.Repository <DeliveryType>().GetById(p => p.DeliveryId.Equals(command.DeliveryTypeId)); var previousVal = deliveryTypeEntity.DeletedDate; deliveryTypeEntity.LastModifiedDate = System.DateTime.Now; deliveryTypeEntity.DeletedDate = null; uow.Repository <DeliveryType>().Update(deliveryTypeEntity); uow.SubmitChanges(); //log //Inset new Activity var activity = new Activity() { Source = "Loại hàng", Source_Id = deliveryTypeEntity.DeliveryId, Action = "Sửa", Previous_value = previousVal.ToString(), Current_value = null, CreatedDate = System.DateTime.Now, CreatedBy = command.UserId }; iActivityServices.AddActivity(new ActivityAddCommand { Activity = activity }); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception) { throw; } } }
public async Task <ActionResult> Create(ActivityCreateEditViewModel viewModel) { if (ModelState.IsValid) { viewModel.Id = Guid.NewGuid(); var model = viewModel.ToModel(); model.UserId = User.Identity.GetUserId(); await _activityService.AddActivity(model); return(RedirectToAction("Index")); } return(View("CreateEdit", viewModel)); }
public void Handle(StatusAddCommand command) { using (var uow = new UnitOfWork <EF>()) { try { //add var statusEntity = new Status() { StatusId = Guid.NewGuid().ToString(), Name = command.Status.Name, Description = command.Status.Description, CreatedDate = System.DateTime.Now, LastModifiedDate = System.DateTime.Now }; uow.Repository <Status>().Add(statusEntity); uow.SubmitChanges(); //Insert new Activity var activity = new Activity(); activity.Source = "Trạng thái"; activity.Source_Id = statusEntity.StatusId; activity.Action = "Tạo"; activity.Current_value = statusEntity.Name; activity.CreatedDate = System.DateTime.Now; activity.CreatedBy = command.Status.UserId; iActivityServices.AddActivity(new ActivityAddCommand { Activity = activity }); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception) { throw; } } }
public void Handle(StatusUpdateDescriptionCommand command) { using (var uow = new UnitOfWork <EF>()) { try { //update var statusEntity = uow.Repository <Status>().GetById(p => p.StatusId.Equals(command.StatusId)); var previousVal = statusEntity.Description; statusEntity.LastModifiedDate = System.DateTime.Now; statusEntity.Description = command.Description; uow.Repository <Status>().Update(statusEntity); uow.SubmitChanges(); //Insert new Activity var activity = new Activity() { Source = "Trạng thái", Source_Id = statusEntity.StatusId, Action = "Sửa", Previous_value = previousVal, Current_value = command.Description, CreatedDate = System.DateTime.Now, CreatedBy = command.UserId }; iActivityServices.AddActivity(new ActivityAddCommand { Activity = activity }); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception) { throw; } } }
public ActionResult Add(ActivitiesViewModel model) { string errorMessage = "Unable to add the activity to the package."; string successMessage = "The activity has been added to your package."; if (ModelState.IsValid) { try { // Get co-ordianates of address IGeolocationService geolocationService = UtilityFactory.GetGeolocationService(); Location location = geolocationService.GetCoordinates( String.Format("{0}, {1}, {2}", model.Address, model.PackageCity, model.PackageState.ToString())); Activity activity = new Activity() { Name = model.ActivityName, Description = model.Description, Address = model.Address, Status = PackageStatusEnum.Available, PackageId = model.PackageId, Latitude = location.Latitude, Longitude = location.Longitude }; ResultEnum result = activityService.AddActivity(activity); if (result == ResultEnum.Success) { model.SuccessMessage = successMessage; } else { model.ErrorMessage = errorMessage; } return(View(model)); } catch { model.ErrorMessage = errorMessage; } } return(View(model)); }
public void Handle(MerchandiseTypeDeleteCommand command) { using (var uow = new UnitOfWork <EF>()) { try { //delete var merchandiseTypeEntity = uow.Repository <MerchandiseType>().GetById(p => p.MerchandiseId.Equals(command.MerchandiseId) && !p.DeletedDate.HasValue); merchandiseTypeEntity.DeletedDate = System.DateTime.Now; merchandiseTypeEntity.LastModifiedDate = System.DateTime.Now; uow.Repository <MerchandiseType>().Update(merchandiseTypeEntity); uow.SubmitChanges(); //Insert new Activity var activity = new Activity(); activity.Source = "Loại Hàng"; activity.Source_Id = merchandiseTypeEntity.MerchandiseId; activity.Action = "Tạo"; activity.Current_value = merchandiseTypeEntity.Name; activity.CreatedDate = System.DateTime.Now; activity.CreatedBy = command.UserId; iActivityServices.AddActivity(new ActivityAddCommand { Activity = activity }); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } catch (Exception) { throw; } } }
public IActionResult Create([FromBody] Activity activity) { var model = new ActivityViewModel(); try { model = mapper.Map <ActivityViewModel>(activityService.AddActivity(activity)); model.MessageType = MessageTypeEnum.success; model.Message = "Actividad creada"; } catch (Exception) { model.MessageType = MessageTypeEnum.danger; model.Message = "Error en la aplicación"; } model.ShowMessage = true; return(Json(model)); }
public IActionResult Post([FromBody] ActivityRequest activity) { _service.AddActivity(activity); return(Ok()); }
public async Task <IActionResult> AddActivity(CreateActivityRequest request) { return(Ok(await _activityService.AddActivity(request))); }