public async Task <CreatedEntity <int> > Handle(CreateWorkerInfo request, CancellationToken cancellationToken) { var workerInfo = _mapper.Map <CreateWorkerInfo, WorkerInfo>(request); _workerInfoRepository.Add(workerInfo); await _unitOfWork.CommitAsync(); return(new CreatedEntity <int>() { Id = workerInfo.Id }); }
public async Task <CreatedEntity <int> > Handle(CreateArticle request, CancellationToken cancellationToken) { var article = _mapper.Map <CreateArticle, Article>(request); _articleRepository.Add(article); await _unitOfWork.CommitAsync(); return(new CreatedEntity <int>() { Id = article.Id }); }
public IActionResult Post([FromBody] AktuelDetail aktuelDetail) { try { _repo.Add(aktuelDetail); return(new StatusCodeResult(201)); } catch { } return(BadRequest()); }
public IActionResult Post([FromBody] Company company) { try { _repo.Add(company); return(new StatusCodeResult(201)); } catch { } return(BadRequest()); }
public void Add_Tenant_ReturnOkay() { #region Init data var tenant = new Tenant { Name = "Nam", Description = "Description", Number = 1, ScheduleTimer = 1000, IsEnabled = true, CreatedBy = 1, CreatedDate = DateTime.UtcNow }; try { _tenants.Add(tenant); _dbContext.Save(); } catch (Exception ex) { Assert.Fail("Add fail"); return; } #endregion #region Get and check data var actualTenant = _tenants.Query().FirstOrDefault(t => t.Id == tenant.Id); Assert.IsNotNull(actualTenant); Assert.AreEqual(tenant.Id, actualTenant.Id); Assert.AreEqual(tenant.Name, actualTenant.Name); Assert.AreEqual(tenant.Description, actualTenant.Description); Assert.AreEqual(tenant.Number, actualTenant.Number); Assert.AreEqual(tenant.ScheduleTimer, actualTenant.ScheduleTimer); Assert.AreEqual(tenant.IsEnabled, actualTenant.IsEnabled); #endregion #region Clean data if (actualTenant != null) { _tenants.Delete(actualTenant); _dbContext.Save(); } #endregion }
public IActionResult EditCategory(Category category) { if (category.ID == 0) { repository.Add(category); } else { repository.Edit(category); } repository.Save(); return(RedirectToAction(nameof(Index))); }
public bool Add(User entity) { try { _userRepository.Add(entity); _userRepository.SubmitChanges(); return(true); } catch (Exception) { return(false); } }
public bool AddGlossary(Glossary glossary) { try { _glossaryRepository.Add(glossary); _glossaryRepository.SubmitChanges(); return(true); } catch (Exception) { return(false); } }
public virtual ActionResult Create(ViewModels.Enterprise.Create createViewModel) { if (ModelState.IsValid) { var enterprise = Mapper.Map <Enterprise>(createViewModel); enterprise.Password = _accountService.HashPassword(enterprise.Password); enterprise.UserName = enterprise.Email; _enterpriseRepository.Add(enterprise); //ADD NOTIFICATIONS: À la coordination et aux autres employés de l'entreprise. return(RedirectToAction(MVC.Home.Index())); } return(View(createViewModel)); }
public virtual ActionResult Create(ViewModels.ContactEnterprise.Create createViewModel) { var list = _contactEnterpriseRepository.GetAll(); if (list != null) { var email = list.FirstOrDefault(x => x.Email == createViewModel.Email); if (email != null) { this.Flash(FlashMessageResources.ErrorsOnPage, FlashEnum.Error); ModelState.AddModelError("Email", ContactEnterpriseResources.EmailContactEnterpriseAlreadyUsed); } } if (ModelState.IsValid) { var newContactEnterprise = Mapper.Map <ContactEnterprise>(createViewModel); newContactEnterprise.Active = true; newContactEnterprise.Password = _accountService.HashPassword(newContactEnterprise.Password); newContactEnterprise.UserName = newContactEnterprise.Email; newContactEnterprise.Roles = new List <UserRole>() { new UserRole() { RoleName = RoleName.ContactEnterprise } }; _contactEnterpriseRepository.Add(newContactEnterprise); string message = String.Format(ContactEntrepriseToCoordinator.CreateContactEnterprise, newContactEnterprise.FirstName, newContactEnterprise.LastName); _notificationService.SendNotificationToAllCoordinator( ContactEntrepriseToCoordinator.CreateContactEnterpriseTitle, message); _mailler.SendEmail(newContactEnterprise.Email, EmailAccountCreation.Subject, EmailAccountCreation.Message + EmailAccountCreation.EmailLink); this.Flash(FlashMessageResources.CreateAccountSuccess, FlashEnum.Success); return(RedirectToAction(MVC.ContactEnterprise.CreateConfirmation(newContactEnterprise.Id))); } return(View(createViewModel)); }
private void SendNotification(int id, String title, String message) { var notification = new Notification() { Date = DateTime.Now, Title = title, Message = message, For = id, Seen = false }; _notificationRepository.Add(notification); }
private ShipmentState InsertShipmentState(Guid ShipmentKey, ShipmentStatus status) { var shipmentState = new ShipmentState { Key = Guid.NewGuid(), ShipmentKey = ShipmentKey, ShipmentStatus = status, CreatedOn = DateTime.Now }; _shipmentStateRepository.Add(shipmentState); _shipmentStateRepository.Save(); return(shipmentState); }
private void Add() { Entity entity = entityFactory.Create("hourseprice"); entity.Initialize(Helper.FormToDictionary()); IEntityRepository Repo = factory.Create("hourseprice"); entity = Repo.Add(entity); if (string.IsNullOrEmpty(Repo.ErrorMessage)) { Helper.Response(entity.Serialize()); } }
public void CriarLogMovimento(int gameId, int disco, int origem, int destino) { movimentoLogRepository.Add(new MovimentoLog { Movimento = new Movimento { GameId = gameId, DiscoId = disco, OrigemId = origem, DestinoId = destino }, Data = DateTime.Now }); }
public IActionResult Add(CreateAnswerDto answerDto) { if (ModelState.IsValid) { if (questionRepository.IsExist(answerDto.QuestionId)) { var answer = mapper.Map <Answer>(answerDto); var ans = repository.Add(answer); return(StatusCode(201, ans)); } return(BadRequest("Invalid Question Id")); } return(BadRequest()); }
public void NotifyNewInternshipOfferCreated(int internshipOfferAuthorId) { var employee = _employeeRepository.GetById(internshipOfferAuthorId); var allCoordinators = _coordinatorRepository.GetAll().AsEnumerable(); const string ACTION_NAME = "CoordinatorIndex"; const string CONTROLLER_NAME = "InternshipOffer"; foreach (var coordinator in allCoordinators) { var notification = new Notification() { Object = WebMessage.NotificationMessage.NewInternshipOfferCreatedMessage(employee.Company.Name, employee.FullName()), SenderId = employee.Id, ReceiverId = coordinator.Id, Unseen = true, Time = DateTime.Now, LinkAction = ACTION_NAME, LinkController = CONTROLLER_NAME }; _notificationRepository.Add(notification); } }
public ClaimsIdentity Register(string userEmail, string password) { if (IsRegisteredUser(userEmail)) { return(null); } userRepository.Add(new UserDbo() { Email = userEmail, Password = Encryption.EncryptPasswordMD5(password, userEmail) }); return(Login(userEmail)); }
public async Task <CreatedEntity <int> > Handle(CreateWorkerRun request, CancellationToken cancellationToken) { var workerRun = _mapper.Map <CreateWorkerRun, WorkerRun>(request); _workerRunRepository.Add(workerRun); await _unitOfWork.CommitAsync(); await _messagingService.SendAsync(StartWorkerRun.QueueName, new StartWorkerRun(workerRun.Id)); return(new CreatedEntity <int>() { Id = workerRun.Id }); }
public Tweet CreateTweet(Tweet tweet, IEnumerable <Hashtag> hashtags) { //save the tweet tweet.Key = Guid.NewGuid(); tweet.CreatedOn = DateTime.Now; _tweetRepository.Add(tweet); _tweetRepository.Save(); AssociateTweetWithHashtags(tweet, hashtags); return(tweet); }
public virtual ActionResult CreateStage(ViewModels.Stage.Create createdStage) { if (!ModelState.IsValid) { return(View(createdStage)); } var stage = Mapper.Map <Stage>(createdStage); stage.PublicationDate = DateTime.Now; _stageRepository.Add(stage); return(RedirectToAction(MVC.Enterprise.CreateStageSucceed())); }
public virtual ActionResult CreateListPost() { var listStudentNotAdded = new List <ListStudent>(); var listStudentAdded = new List <ListStudent>(); var listStudentInDb = _studentRepository.GetAll().ToList(); var listStudents = TempData["listStudent"] as List <ListStudent>; var alreadyInDb = false; if (listStudents == null) { ModelState.AddModelError("Error", "Error"); } if (ModelState.IsValid) { foreach (var listStudentCreate in listStudents) { for (int i = 0; i < listStudentInDb.Count(); i++) { if (!alreadyInDb) { if (listStudentInDb[i].Matricule == listStudentCreate.Matricule) { listStudentNotAdded.Add(listStudentCreate); alreadyInDb = true; } } } if (Convert.ToInt32(listStudentCreate.Matricule) < 1000000 || Convert.ToInt32(listStudentCreate.Matricule) > 9999999) { listStudentNotAdded.Add(listStudentCreate); alreadyInDb = true; } if (!alreadyInDb) { var student = Mapper.Map <Student>(listStudentCreate); listStudentAdded = listStudents; _studentRepository.Add(student); } alreadyInDb = false; } TempData["listStudentNotAdded"] = listStudentNotAdded; TempData["listStudentAdded"] = listStudentAdded; return(RedirectToAction(MVC.Coordinator.ResultCreateList())); } return(RedirectToAction(MVC.Coordinator.Upload())); }
public virtual Result <T> Add(T entity) { var result = new Result <T>(); try { var adding = _repository.Add(entity); var uow = _unitOfWork.Commit(); if (uow > 0) { result.ResultObject = adding; result.ResultCode = (int)ResultStatusCode.Created; result.ResultMessage = $"'{ClassFullName}' successfully created"; result.ResultStatus = true; result.ResultInnerMessage = $"'{result.ResultMessage}' => {result.ResultObject}"; } else { result.ResultObject = adding; result.ResultCode = (int)ResultStatusCode.BadRequest; result.ResultMessage = $"'{ClassFullName}' not created"; result.ResultStatus = false; result.ResultInnerMessage = $"'{result.ResultMessage}' => {result.ResultObject}"; } } catch (Exception ex) { result.ResultCode = (int)ResultStatusCode.BadRequest; result.ResultMessage = ex.Message; result.ResultInnerMessage = ex.InnerException?.ToString(); result.ResultStatus = false; result.ResultObject = null; } return(result); }
public virtual ActionResult Create(Create create) { if (ModelState.IsValid) { var review = Mapper.Map <Review>(create); review.WriterId = _httpContextService.GetUserId(); _reviewRepository.Add(review); return(RedirectToAction(MVC.Home.Index())); } PopulateRestaurantSelectList(create); return(View(create)); }
public void SaveNewRevision(Guid poemId, RevisionDTO newRevision) { var poemEntity = _poemRepository.GetByGuid(poemId); if (poemEntity == null) { throw new ApplicationException(); } var revisionEntity = newRevision.ToEntity(); revisionEntity.Poem = poemEntity; revisionEntity.CreatedDateUTC = DateTime.UtcNow; _revisionRepository.Add(revisionEntity); }
public IActionResult Add(int p = 11, int q = 3) { string cart = GetCart(); BasketLine basketLine = new BasketLine { BasketID = cart, ProductID = p, Quantity = q }; repository.Add(basketLine); repository.Save(); SaveCart(cart); return(RedirectToAction(nameof(Index))); }
public async Task <int> Handle(AddUserCommand request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var user = _mapper.Map <User>(request); await _repository.Add(user); await _work.Commit(cancellationToken); return(user.Id); }
public OperationResult <ShipmentType> AddShipmentType(ShipmentType shipmnetType) { if (_shipmentTypeRepository.GetSingleByName(shipmnetType.Name) != null) { return(new OperationResult <ShipmentType>(false)); } shipmnetType.Key = Guid.NewGuid(); shipmnetType.CreatedOn = DateTime.Now; _shipmentTypeRepository.Add(shipmnetType); _shipmentTypeRepository.Save(); return(new OperationResult <ShipmentType>(true) { Entity = shipmnetType }); }
public async Task <int> Handle(AddProjectCommand request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var project = _mapper.Map <Project>(request); await _repository.Add(project); await _work.Commit(cancellationToken); return(project.Id); }
public async Task <int> Handle(AddTaskCommand request, CancellationToken cancellationToken) { if (request is null) { throw new ArgumentNullException(nameof(request)); } var task = _mapper.Map <Domain.Task>(request); await _repository.Add(task); await _work.Commit(cancellationToken); return(task.Id); }
public void Add_User_ReturnOkay() { #region Init data var user = new User { FirstName = "Nam", LastName = "Nguyen", Email = "*****@*****.**", CultureId = 1, Password = "******", SaltPassword = "******", Comment = "comment", IsEnabled = true, CreatedBy = 1, CreatedDate = DateTime.UtcNow, }; _users.Add(user); _dbContext.Save(); #endregion #region Get and check var actualUser = _users.Query().FirstOrDefault(t => t.Id == user.Id); Assert.IsNotNull(actualUser); Assert.AreEqual(user.Id, actualUser.Id); //Assert.AreEqual(user.UserName, actualUser.UserName); Assert.AreEqual(user.CultureId, actualUser.CultureId); Assert.AreEqual(user.Password, actualUser.Password); Assert.AreEqual(user.SaltPassword, actualUser.SaltPassword); Assert.AreEqual(user.Comment, actualUser.Comment); Assert.AreEqual(user.IsEnabled, actualUser.IsEnabled); #endregion #region Clean data if (actualUser != null) { _users.Delete(actualUser); _dbContext.Save(); } #endregion }