public async Task <Message> PostCompany([FromBody] CompanyCreation companyCreation) { if (companyCreation == null) { return(Message.Fail()); } var dbitem = await _companyRepository.GetSingleAsync(x => x.Name == companyCreation.Name); if (dbitem != null) { return(Message.Fail().Add("content", "公司重复")); } companyCreation.Id = Method.GetGuid32(); companyCreation.ParentId = "0"; var newItem = _mapper.Map <Company>(companyCreation); _companyRepository.Add(newItem); if (!await _unitOfWork.SaveAsync()) { return(Message.ServerError()); } return(Message.Ok()); }
public static void GenerateStartupInfo(ICompanyRepository companyRepo, IOfficeRepository officeRepo) { var company1 = new Company() { Id = Guid.NewGuid(), Name = "The Big Great Company", CEO = "Peter Johnson", OfficeIds = new List <Guid>() }; var office1 = new Office() { Id = Guid.NewGuid(), BuildingName = "Building Numer One", Street = "Downstreet", HouseNumber = 1, City = "Boston", }; company1.OfficeIds.Add(office1.Id); companyRepo.Add(company1); officeRepo.Add(office1); var company2 = new Company() { Id = Guid.NewGuid(), Name = "The Small Company", CEO = "Jan Janssen", OfficeIds = new List <Guid>() }; companyRepo.Add(company2); }
public async Task <Company> CreateCompany(CreatePageRequest request, User user) { if (user == null) { Notify("User not found"); } var city = await _cityRepository.GetById(request.CityId); if (city == null) { Notify("City not found"); } if (!HasNotification()) { var newCompany = new Company(request.Name, city, request.LinkedIn, user); await _companyRepository.Add(newCompany); return(await _companyRepository.GetById(newCompany.Id)); } else { return(null); } }
public async Task <string> Register(RegisterModel registerModel) { if (await _companyRepository.IsNameDuplicate(registerModel.CompanyName)) { throw new Exception($"'{registerModel.CompanyName}' already exists. Please choose a different name."); } var company = new Core.Model.Company(registerModel.CompanyName); _companyRepository.Add(company); await _companyRepository.SaveChanges(); var user = new Core.Model.User(company, registerModel.Email, registerModel.Username); var identityResult = await userManager.CreateAsync(user, registerModel.Password); if (identityResult.Succeeded) { await signInManager.SignInAsync(user, isPersistent : false); return(GetToken(user)); } else { _companyRepository.Remove(company); await _companyRepository.SaveChanges(); throw new Exception(identityResult?.Errors?.First()?.Description); } }
public ActionResult Add(CompanyViewModel cvm) { var company = Mapper.Map <Company>(cvm); var status = _companyRepo.Add(company); return(Json(new { result = status ? "true" : "false" }, JsonRequestBehavior.AllowGet)); }
public void AddTest() { Company company = new Company(); company.Name = "My Test Company"; repository.Add(company); this.unitOfWork.Commit(); Company savedCompany = this.repository.FindBy(company.Key); Assert.AreEqual("My Test Company", savedCompany.Name); this.repository.Remove(savedCompany); this.unitOfWork.Commit(); }
public async Task <IActionResult> LikeUser(int id, int recipientId) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var like = await _repo.GetLike(id, recipientId); if (like != null) { return(BadRequest("You already like this user")); } if (await _repo.GetUser(recipientId, false) == null) { return(NotFound()); } like = new Like { LikerId = id, LikeeId = recipientId }; _repo.Add <Like>(like); if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to like user")); }
public IActionResult AddCompany([FromBody] CompanyCreateDto companyDto) { if (companyDto is null) { return(BadRequest(ModelState)); } if (_companyRepository.Exists(c => c.Name == companyDto.Name)) { ModelState.AddModelError("", "Company already exists in the database"); return(StatusCode(500, ModelState)); } Company company = _mapper.Map <Company>(companyDto); _companyRepository.Add(company); if (_companyRepository.Save() > 0) { return(CreatedAtRoute("GetCompany", company.Id, company)); } else { ModelState.AddModelError("", "Something went erong saving the company"); return(StatusCode(500, ModelState)); } }
private void EnrichQuotes(List <StockQuote> quotes, DateTime date) { var allQuotesFromPreviousSession = _stockQuoteRepository.GetAllQuotesFromPreviousSession(date).ToHashSet(); foreach (var quote in quotes) { quote.Company = _companyRepository.GetById(quote.Ticker); if (quote.Company == null) { var newCompanyEntity = new Company { Ticker = quote.Ticker }; quote.Company = newCompanyEntity; _companyRepository.Add(newCompanyEntity); _companyRepository.SaveChanges(); } else { quote.PreviousStockQuote = allQuotesFromPreviousSession.SingleOrDefault(x => x.Ticker.Equals(quote.Ticker)); if (quote.PreviousStockQuote != null) { quote.AveragePriceChange = (quote.AveragePrice - quote.PreviousStockQuote.AveragePrice) / quote.PreviousStockQuote.AveragePrice; } else { _logger.LogWarning($"Inconsistent state. {quote.Ticker} is present in database, yet it does not have any record from previous session dated in {allQuotesFromPreviousSession.First().DateParsed.ToShortDateString()}" + $"Add it to blacklist or data fix manually."); } } quote.DateParsed = DateTime.ParseExact(quote.Date.ToString(), "yyyyMMdd", CultureInfo.InvariantCulture); } }
public ActionResult <Company> Add(Guid userId, [FromForm] CompanyForAddResource companyForAddDto) { _repo.Add(userId, companyForAddDto); var data = _repo.GetList(userId); return(Ok(new { data })); }
public ActionResult Add(CompanyVM model) { try { var modelAdd = model.search.GetEntity(); var msgValid = ValidateModel(modelAdd); if (string.IsNullOrEmpty(msgValid)) { var obj = _userRepository.Add(modelAdd); if (obj) { return(Json(new { status = true })); } else { return(Json(new { status = false, msg = "Thêm thất bại" })); } } else { return(Json(new { status = false, msg = msgValid })); } } catch (Exception ex) { // chuyển sang page ERR return(RedirectToAction("Index", "Error")); } }
public string RegisterCompany(Company company) { company.Token = Guid.NewGuid().ToString(); companiesRepository.Add(company); SaveCompany(); return(company.Token); }
public async Task <IActionResult> InsertCompany(CompanyForInsertDTO companyForInsertDTO) { /* * --------------------------------------------------------------------------- * ZONA DE VALIDACION * --------------------------------------------------------------------------- */ /* * -------------------------------------------------------------------------- * ZONA DE PROCESAMIENTO DE LA PETICION * -------------------------------------------------------------------------- */ // Paso 1: Crear objeto y mapearlo con el DTO var company = new Company(); _mapper.Map(companyForInsertDTO, company); // Paso 2: Insertar al repositorio _companyRepository.Add(company); await _companyRepository.SaveAll(); // Paso 3: retornamos respuesta return(Ok()); }
public async Task <IActionResult> CreateMessage(int userId, MessageForCreationDto messageForCreationDto) { var sender = await _repo.GetUser(userId, false); if (sender.Id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } messageForCreationDto.SenderId = userId; var recipient = await _repo.GetUser(messageForCreationDto.RecipientId, false); if (recipient == null) { return(BadRequest("Could not find user")); } var message = _mapper.Map <Message>(messageForCreationDto); _repo.Add(message); if (await _repo.SaveAll()) { var messageToReturn = _mapper.Map <MessageToReturnDto>(message); return(CreatedAtRoute("GetMessage", new { id = message.Id }, messageToReturn)); } throw new Exception("Creating the message failed on save"); }
public IHttpActionResult PostCompany(Company company) { bool companyExists = _companyRepository.GetAll().Any( x => x.CompanyEmail == company.CompanyEmail || x.CompanyPhone == company.CompanyPhone); if (companyExists) { ModelState.AddModelError("Error", "This Company Already Exists."); } if (ModelState.IsValid) { try { _companyRepository.Add(company); return(CreatedAtRoute("DefaultApi", new { id = company.CompanyID }, company)); } catch (Exception ex) { return(BadRequest("Failed During Company Creation. Error: " + ex.Message)); } } else { return(BadRequest(ModelState)); } }
public virtual ActionResult CreateCompany(Company model) { _companyRepository.Add(model); _unitOfWork.Commit(); return(RedirectToAction("Companies")); }
public SYS_CompanyDTO AddCompany(SYS_Company item, string source) { IUnitOfWork unitOfWork = _CompanyRepository.UnitOfWork; SYS_CompanyDTO entityDTO = null; int count = _CompanyRepository.FindBy(c => c.WorkSpaceId == item.WorkSpaceId && c.Code == item.Code && !c.Canceled).Count(); if (count > 0) { throw new Exception(MsgConfig.MsgCodeCompany); } if (_CompanyRepository.IsValidAdd(item.WorkSpaceId)) { try { _CompanyRepository.Add(item); unitOfWork.Commit(); entityDTO = Mapper.Map <SYS_CompanyDTO>(item); } catch (Exception ex) { _log.Error(ex.Message, ex.Source, ex.StackTrace, source); throw new Exception(MsgConfig.MsgAddError); } } else { _log.Warning(MsgConfig.MsgMaxCompaniesWarning, typeof(CompanyManagementService).Assembly.FullName, source); throw new Exception(MsgConfig.MsgMaxCompaniesError); } return(entityDTO); }
public async Task <CompanyViewModel> Add(CompanyViewModel companyViewModel) { var company = _mapper.Map <Company>(companyViewModel); company.Id = Guid.NewGuid(); company.AddressId = Guid.NewGuid(); company.Address.Id = company.AddressId.Value; if (!ExecuteValidation(new CompanyValidation(), company) || !ExecuteValidation(new AddressValidation(), company.Address)) { return(null); } if (_companyRepository.Get(c => c.Document == company.Document).Result.Any()) { Notify("There is already a company with the document informed."); return(null); } await _companyRepository.Add(company); return(_mapper.Map <CompanyViewModel>(company)); }
public bool CreateCompany(CompanyVM _CompanyVM) { try { tblCompany company = new tblCompany(); company.Address = _CompanyVM.Address; company.BankAccountNo = _CompanyVM.BankAccountNo; company.BankIFSCNo = _CompanyVM.BankIFSCNo; company.BankName = _CompanyVM.BankName; company.City = _CompanyVM.City; company.CompanyName = _CompanyVM.CompanyName; company.CountryId = _CompanyVM.CountryId; company.Email = _CompanyVM.Email; company.FaxNo = _CompanyVM.FaxNo; company.GSTIN = _CompanyVM.GSTIN; company.IsActive = _CompanyVM.IsActive; company.Logo = _CompanyVM.Logo; company.LogoPath = _CompanyVM.LogoPath; company.MobileNo = _CompanyVM.MobileNo; company.Password = _CompanyVM.Password; company.PinCode = _CompanyVM.PinCode; company.State = _CompanyVM.State; company.TelephoneNo = _CompanyVM.TelephoneNo; company.Website = _CompanyVM.Website; _companyRepository.Add(company); _unitOfWork.Complete(); return(true); } catch (Exception e) { throw e; } }
public IActionResult Post([FromBody] Company item) { var id = _companyRepository.Add(item); var data = _companyRepository.Get(id); return(CreatedAtRoute("GetCompany", new { id = id }, data)); }
public ActionResult Add(CompanyDTO entity) { //Company com = new Company(); //com.CompanyName = entity.CompanyName; //com.ContactName = entity.ContactName; //com.ContactTitle = entity.ContactTitle; //com.AddressID = entity.AddressID; //com.Phone = entity.Phone; //com.Fax = entity.Fax; //com.Website = entity.Website; //com.IsSupplier = entity.IsSupplier; //companyRepository.Add(com); //companyRepository.Save(); //return Json(entity, JsonRequestBehavior.AllowGet); try { Company company = Mapper.Map <CompanyDTO, Company>(entity); companyRepository.Add(company); companyRepository.Save(); return(Json(entity, JsonRequestBehavior.DenyGet)); } catch (Exception e) { return(Json(false, JsonRequestBehavior.DenyGet)); } }
public async Task <IActionResult> CreateCompany([FromBody] SaveCompanyResource companyResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var specialists = await repository.GetListOfSpecialistsIds(); var usersToCheck = companyResource.Specialists.ToList(); foreach (var i in usersToCheck) { if (!specialists.Contains(i)) { return(BadRequest("Wrong type of users provided")); } } var company = mapper.Map <SaveCompanyResource, Company>(companyResource); repository.Add(company); await unitOfWork.CompleteAsync(); company = await repository.GetCompany(company.Id); var result = mapper.Map <Company, CompanyResource>(company); return(Ok(result)); }
public async Task <CustomResults <string> > Add(CompanyDTO company) { var results = new CustomResults <string>(); try { if (company != null) { if (string.IsNullOrEmpty(company.Name)) { results.StatusCode = HttpStatusCode.BadRequest; results.Message = "Name cannot but null or empty!"; return(results); } if (company.EstablishmentYear <= -1 || company.EstablishmentYear > DateTime.Now.Year) { results.StatusCode = HttpStatusCode.BadRequest; results.Message = "Wrong Establishment year"; return(results); } if (company.Id != 0) { results.StatusCode = HttpStatusCode.BadRequest; results.Message = "Passed ID will be ignored since ORM is creating ID automatically."; return(results); } var isDuplicated = await _companyRepository.FindByName(company.Name); if (isDuplicated != null) { results.StatusCode = HttpStatusCode.BadRequest; results.Message = "Company with that name already exists."; return(results); } var mappedCompany = _mapper.Map <Company>(company); if (mappedCompany != null) { var result = await _companyRepository.Add(mappedCompany); if (result != -1) { results.StatusCode = HttpStatusCode.BadRequest; results.Result = $"Company added successfully. Generated ID's {result}"; } } } } catch (Exception ex) { results.StatusCode = HttpStatusCode.InternalServerError; results.Message = ex.Message; } return(results); }
public IActionResult Manage(string name) { _repository.Add(new CompanyModel() { Name = name }); return(RedirectToAction(nameof(Manage))); }
public CompanyDetail Add(CompanyDetailViewModel Vm) { var entity = _mapper.Map <CompanyDetail>(Vm); entity.CompanyCode = _companyRepository.GenCompanyCode(Vm.CompanyName); _companyRepository.Add(entity); return(entity); }
public async Task AddCompany(CompaniesDto AddCompany) { await _companyRepository.Add(_Mapper.Map <Companies>(AddCompany)); await _companyRepository.Commit(); await _companyRepository.DisposeAsync(); }
/// <inheritdoc /> public async Task HandleAsync(RegisterCompanyCommand command) { var company = new Company(new CompanyName(command.Name), new NationalId(command.NationalId)); _companyRepository.Add(company); await _unitOfWork.CommitAsync(); }
public async Task <int> Add(CompanyViewModel viewmodel) { var company = new Company(); company = JsonConvert.DeserializeObject <Company>(JsonConvert.SerializeObject(viewmodel)); return(await _companiesRepository.Add(company)); }
public void Add(CompanyDTO companyDto) { var company = new Company(); company.Name = companyDto.Name; company.ImageBase64 = companyDto.ImageBase64; _companyRepository.Add(company); }
public async Task <IActionResult> Create([Bind("CompanyId,Name,Address,City,State,PostalCode")] Company company) { if (ModelState.IsValid) { _compRepo.Add(company); return(RedirectToAction(nameof(Index))); } return(View(company)); }