public bool createCompany(CompaniesViewModel model) { if (!checkCreateCompany(model)) { return(false); } Companies createModel = new Companies(); createModel = _mapper.Map <Companies>(model); if (model.companyTypeChoose == "0") { createModel.companyType = CompaniesTypeEnum.personel; } else { createModel.companyType = CompaniesTypeEnum.lls; } createModel.userId = _usersService.getUserInformation(_cookieService.getSessionEmail()).userId; _mainContext.companies.Add(createModel); if (_mainContext.SaveChanges() > 0) { return(true); } else { return(false); } }
public IActionResult AddCompany([FromBody] CompaniesViewModel companyViewModel) { try{ Company company = Mapper.Map <CompaniesViewModel, Company>(companyViewModel); company.UserId = IdentityHelper.GetUserId(HttpContext); company.CreationDate = DateTime.Now; company.LastUpdate = DateTime.Now; company.ReminderDate = DateTime.Now.AddMonths(1); _companiesRepository.AddCompany(company); string content = "A new company listing has been added\n" + "\nID: " + company.CompanyId + "\nCompany name: " + company.CompanyName + "\n\nPlease go to https://capstone1.azurewebsites.net/admin to approve this company listing"; string subject = "New company listing"; _emailService.SendToAdmins(subject, content); return(Ok()); } catch (Exception ex) { return(BadRequest()); } }
public void UpdateCompany(CompaniesViewModel company) { Company oldCompany = GetCompanyById_model(company.CompanyId.Value); _context.Companies.Attach(oldCompany); oldCompany.LastUpdate = DateTime.Now; oldCompany.ReminderDate = DateTime.Now.AddMonths(1); oldCompany.ContactEmail = company.ContactEmail; oldCompany.CompanyName = company.CompanyName; oldCompany.Logo = company.Logo; oldCompany.Size = company.Size; oldCompany.BusinessType = company.BusinessType; oldCompany.SpecialistArea = company.SpecialistArea; oldCompany.CompanyDesc = company.CompanyDesc; oldCompany.Phone = company.Phone; oldCompany.Email = company.Email; oldCompany.Address1 = company.Address1; oldCompany.Address2 = company.Address2; oldCompany.Suburb = company.Suburb; oldCompany.PostalCode = company.PostalCode; oldCompany.City = company.City; oldCompany.Country = company.Country; oldCompany.SummerJobs = company.SummerJobs; oldCompany.Website = company.Website; // I don't think these are necassary because you can't pass them with the view model // _context.Entry(oldCompany).Property(c => c.CompanyId).IsModified = false; // _context.Entry(oldCompany).Property(c => c.IsApproved).IsModified = false; // _context.Entry(oldCompany).Property(c => c.CreationDate).IsModified = false; // _context.Entry(oldCompany).Property(c => c.Users).IsModified = false; _context.SaveChanges(); }
public CompaniesViewModel GetCompanyById_viewModel(int id) { Company company = _context.Companies.SingleOrDefault(x => x.CompanyId == id); CompaniesViewModel viewModel = Mapper.Map <Company, CompaniesViewModel>(company); return(viewModel); }
public string InsertUpdateCompany(CompaniesViewModel _companyObj) { try { AppUA _appUA = Session["AppUA"] as AppUA; _companyObj.commonObj = new CommonViewModel(); _companyObj.commonObj.CreatedBy = _appUA.UserName; _companyObj.commonObj.CreatedDate = _appUA.DateTime; _companyObj.commonObj.UpdatedBy = _appUA.UserName; _companyObj.commonObj.UpdatedDate = _appUA.DateTime; CompaniesViewModel companyObj = Mapper.Map <Companies, CompaniesViewModel>(_companiesBusiness.InsertUpdateCompany(Mapper.Map <CompaniesViewModel, Companies>(_companyObj))); if (_companyObj.Code == "" || _companyObj.Code == null) { return(JsonConvert.SerializeObject(new { Result = "OK", Records = companyObj, Message = "Insertion successfull" })); } else { return(JsonConvert.SerializeObject(new { Result = "OK", Records = companyObj, Message = "Updation successfull" })); } } catch (Exception ex) { AppConstMessage cm = c.GetMessage(ex.Message); return(JsonConvert.SerializeObject(new { Result = "ERROR", Message = cm.Message })); } }
public IActionResult EditCompany([FromBody] CompaniesViewModel company) { try { if (company.CompanyId.HasValue) { if (company.UserId == IdentityHelper.GetUserId(HttpContext)) { _companiesRepository.UpdateCompany(company); return(Ok()); } else { return(Unauthorized()); } } else { return(BadRequest()); } } catch (Exception ex) { return(BadRequest()); } }
public ActionResult Register() { RegisterViewModel model = new RegisterViewModel(); CompaniesViewModel company = new CompaniesViewModel(); model.Company = company; var allCompanyTypes = CompanyTypeManager.GetAll(); //returns List<CompanyTypes> var checkBoxListItems = new List <CheckBoxListItem>(); foreach (var type in allCompanyTypes) { checkBoxListItems.Add(new CheckBoxListItem() { ID = type.Id, Display = type.Type, IsChecked = false //On the add view, no genres are selected by default }); } company.CompanyTypes = checkBoxListItems; return(View(model)); }
public IEnumerable <CompaniesViewModel> GetCompanies() { List <CompaniesViewModel> list = new List <CompaniesViewModel>(); foreach (var item in _context.Companies.ToList()) { CompaniesViewModel company = new CompaniesViewModel { Id = item.Id, Name = item.Name, ContactLastName = item.ContactLastName, ContactName = item.ContactName, Email = item.Email, Enabled = item.Enabled, InitialDate = item.InitialDate?.ToString("dd/MM/yyyy"), Phone = item.Phone, Website = item.Website }; if (!string.IsNullOrEmpty(item.Logo)) { byte[] imageArray = System.IO.File.ReadAllBytes(@item.Logo); string base64ImageRepresentation = Convert.ToBase64String(imageArray); company.Logo = "data:image/png;base64," + base64ImageRepresentation; } list.Add(company); } return(list); }
// GET: Company public ActionResult Index() { CompaniesViewModel CVM = new CompaniesViewModel(); List <SelectListItem> selectListItem = new List <SelectListItem>(); CVM.userObj = new UserViewModel(); CVM.userObj.userList = new List <SelectListItem>(); List <UserViewModel> userList = Mapper.Map <List <User>, List <UserViewModel> >(_userBusiness.GetAllUsers()); foreach (UserViewModel U in userList) { selectListItem.Add(new SelectListItem { Text = U.UserName, Value = U.ID.ToString(), Selected = false }); } CVM.userObj.userList = selectListItem; return(View(CVM)); }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); _model = (CompaniesViewModel)this.DataContext; settingsControl.Source = _model.Settings; }
// // GET: /Company/ public ActionResult Companies(int filmId) { CompaniesViewModel model = new CompaniesViewModel { FilmSubmissionId = filmId, Companies = new CompanyRepository().Companies(filmId) }; return(View("Companies", model)); }
public ActionResult ChangeTableRow(CompaniesViewModel companiesViewModel) { if (!ModelState.IsValid) { return(View(companiesViewModel)); } TempData["result"] = companiesViewModel.ChangeCompany(companiesViewModel.CompanyEntity); return(RedirectToAction("TableView")); }
public IActionResult ListCompanies() { var companiesViewModel = new CompaniesViewModel() { Companies = _context.Company .Include(c => c.CompanyType).ToList() }; return(View(companiesViewModel)); }
public async Task <IActionResult> Edit(int?id) { var company = id.HasValue ? await _db.Companies.Include(x => x.Professionals).SingleOrDefaultAsync(x => x.CompanyId == id) : new Companies(); var viewModel = new CompaniesViewModel(company); return(View(viewModel)); }
public IActionResult Index() { var viewModel = new CompaniesViewModel { Companies = this.companiesService.GetAll <CompanyViewModel>(), }; return(this.View(viewModel)); }
public IActionResult Index(string query = null) { var model = new CompaniesViewModel { Companies = _companyData.GetAll(query), Query = query }; return(View(model)); }
public async Task <IActionResult> Index() { var AllCompanies = await _companyService.GetCompanies(); var vm = new CompaniesViewModel(); vm.ListOfCompanies = AllCompanies.ToList(); return(View(vm)); }
public async Task <IViewComponentResult> InvokeAsync() { var vm = new CompaniesViewModel(); var listOfCompanies = await ctx.Companies.Include(x => x.Stores).ToListAsync(); vm.ListOfCompanies = listOfCompanies; return(View(vm)); }
public async Task <IActionResult> Create([Bind("ID,Name,Trade,CompanyEmail,Street,Town,PostalCode,Voivodeship,Country,OwnerID")] CompaniesViewModel company) { if (ModelState.IsValid) { company.ownerID = HttpContext.Session.GetObjectFromJson <int>("ownerID"); _context.Add(CompanyMapper.MapViewToCompany(company)); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(company)); }
public string GetCompanyDetailsByCode(string Code) { try { CompaniesViewModel CompanyList = Mapper.Map <Companies, CompaniesViewModel>(_companiesBusiness.GetCompanyDetailsByCode(Code)); return(JsonConvert.SerializeObject(new { Result = "OK", Records = CompanyList })); } catch (Exception ex) { AppConstMessage cm = c.GetMessage(ex.Message); return(JsonConvert.SerializeObject(new { Result = "ERROR", Message = cm.Message })); } }
public async Task <ActionResult> Create(CompaniesViewModel viewModel) { try { using (var client = new HttpClient()) { string token = string.Empty; if (HttpContext.User.Identity is ClaimsIdentity identity) { token = User.FindFirst("AcessToken")?.Value; var emailnew = User.Claims.FirstOrDefault(c => c.Type == "email")?.Value; } Uri u = new Uri(ApiUrls.Companies.Create); var json = JsonConvert.SerializeObject(new { viewModel.CompanyName, viewModel.State }); var content = new StringContent(json, Encoding.UTF8, "application/json"); //var content = new FormUrlEncodedContent(new[] // { // new KeyValuePair<string, string>("email",registerViewModel.email), // new KeyValuePair<string, string>("password", registerViewModel.password) // }); //HTTP POST client.SetBearerToken(token); // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); client.Timeout = TimeSpan.FromMilliseconds(10000); //HTTP POST var postTask = await client.PostAsync(u, content); //postTask.Wait(); string result = postTask.Content.ReadAsStringAsync().GetAwaiter().GetResult(); if (postTask.IsSuccessStatusCode) { return(RedirectToAction("Index", "Home")); } ModelState.AddModelError(string.Empty, result); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <IActionResult> GetCompany([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //var company = await _context.Companies.FindAsync(id); var company = await _context.Companies.Include(x => x.CompanySectors).Where(x => x.Id == id).FirstOrDefaultAsync(); CompaniesViewModel viewModel = new CompaniesViewModel { Id = company.Id, Name = company.Name, ContactName = company.ContactName, ContactLastName = company.ContactLastName, Enabled = company.Enabled, InitialDate = company.InitialDate?.ToString("dd/MM/yyyy"), Email = company.Email, Phone = company.Phone, City = company.City, State = company.State, Country = company.Country, Schedule = company.Schedule, Comment = company.Comment, Address = company.Address, Postal = company.Postal, Website = company.Website, Sectors = company.CompanySectors.Select(x => x.SectorId).ToList() }; if (!string.IsNullOrEmpty(company.Logo)) { byte[] imageArray = System.IO.File.ReadAllBytes(@company.Logo); viewModel.LogoName = Path.GetFileName(@company.Logo); string base64ImageRepresentation = Convert.ToBase64String(imageArray); viewModel.Logo = "data:image/png;base64," + base64ImageRepresentation; } if (viewModel == null) { return(NotFound()); } return(Ok(viewModel)); }
public ActionResult GetCompanyImage(CompaniesViewModel company) { if (company == null) { return(null); } string path = Server.MapPath("/") + company.ImageURL; if (!System.IO.File.Exists(path)) { return(null); } byte[] imageByteData = System.IO.File.ReadAllBytes(path); return(File(imageByteData, "image")); }
public static Company MapViewToCompany(CompaniesViewModel companiesViewModel) { Company company = new Company { ID = companiesViewModel.ID, Name = companiesViewModel.Name, Trade = companiesViewModel.Trade, CompanyEmail = companiesViewModel.CompanyEmail, Street = companiesViewModel.Street, Town = companiesViewModel.Town, PostalCode = companiesViewModel.PostalCode, Voivodeship = companiesViewModel.Voivodeship, Country = companiesViewModel.Country, ownerID = companiesViewModel.ownerID }; return(company); }
public async Task <IActionResult> Save(CompaniesViewModel model) { var isEdit = false; Companies c; if (!ModelState.IsValid) { return(View("Edit", model)); } if (model.CompanyId != default(int)) { isEdit = true; c = await _db.Companies.FindAsync(model.CompanyId); model.ApplyTo(c); } else { c = new Companies { Name = model.Name, Address1 = model.Address1, Address2 = model.Address2, City = model.City, State = model.State, Zip = model.Zip, IsActive = model.IsActive }; _db.Add(c); } await _db.SaveChangesAsync(); if (isEdit) { return(RedirectToAction("List")); } else { return(RedirectToAction("Edit", new { id = c.CompanyId })); } }
public static CompaniesViewModel MapCompanyToView(Company company, ApplicationDb context) { CompaniesViewModel vModel = new CompaniesViewModel { ID = company.ID, Name = company.Name, Trade = company.Trade, CompanyEmail = company.CompanyEmail, Street = company.Street, Town = company.Town, PostalCode = company.PostalCode, Voivodeship = company.Voivodeship, Country = company.Country, ownerID = company.ownerID, VoivodeshipName = context.Voivodeships.Where(v => v.ID == company.Voivodeship).Select(v => v.Name).First(), CountryName = context.Countries.Where(v => v.ID == company.Country).Select(v => v.Name).First() }; return(vModel); }
public IActionResult GetCompany([FromQuery] int id) { try { CompaniesViewModel company = _companiesRepository.GetCompanyById_viewModel(id); if (company.IsApproved == 1) { return(Ok(company)); } else { return(BadRequest()); } } catch { return(BadRequest()); } }
bool checkCreateCompany(CompaniesViewModel model) { if (model.adress == null || model.companyTitle == null) { ToastrService.AddToUserQueue(new Toastr("Lütfen adres ve şirket adınızı boş geçmeyiniz.", type: Model.Enums.ToastrType.Warning)); return(false); } else { if (model.companyType == CompaniesTypeEnum.personel) { if (model.identyNumber.ToString() == null) { ToastrService.AddToUserQueue(new Toastr("Lütfen Tc Kimlik numaranızı boş geçmeyiniz.", type: Model.Enums.ToastrType.Warning)); return(false); } else { ToastrService.AddToUserQueue(new Toastr("Başarıyla şirket eklediniz.", type: Model.Enums.ToastrType.Success)); return(true); } } else { if (model.taxCenter == null || model.taxNumber.ToString() == null) { ToastrService.AddToUserQueue(new Toastr("Lütfen Vergi Dairesi ve Vergi Numaranızı boş geçmeyiniz.", type: Model.Enums.ToastrType.Warning)); return(false); } else { ToastrService.AddToUserQueue(new Toastr("Başarıyla şirket eklediniz.", type: Model.Enums.ToastrType.Success)); return(true); } } } }
// GET: Companies public ActionResult Index() { var ownCompanies = _companyManager.GetUserCompanies(User.Identity.GetUserId <int>(), true).ToArray(); // remove all reports not yet completed foreach (var reportPermalinks in ownCompanies.Select(c => c.Permalinks as IList <ReportPermalink> ?? c.Permalinks.ToList())) { for (var i = reportPermalinks.Count - 1; i >= 0; i--) { if (reportPermalinks[i].Status != ReportStatus.Completed) { reportPermalinks.RemoveAt(i); } } } var m = new CompaniesViewModel { OwnCompanies = ownCompanies, OtherCompanies = _companyManager.GetUserCompanies(User.Identity.GetUserId <int>(), false).ToArray() }; return(View(m)); }
public AddCompanyViewModel() { vml = new ViewModelLocator(); qvm = vml.Companies; AddCompanyCommand = new RelayCommand(AddCompany); }
private void btnCompanies_Click(object sender, RoutedEventArgs e) { DataContext = new CompaniesViewModel(); }