public ActionResult DepartmentMenuPartial() { CompanyVM companyVM = new CompanyVM(); //var departments = _repo.GetDepartments().ToList(); //companyVM.DepartmentDtos = departments; var departments = _repo.GetDepartments(); var categories = new List <CategoryDto>(); var companies = new List <CompanyDto>(); for (int i = 0; i < departments.Count(); i++) { var deptId = departments[i].Id; categories = _repo.GetCategoryWithDeptId(deptId).ToList(); companyVM.DepartmentDtos = departments; for (int j = 0; j < categories.Count(); j++) { companyVM.DepartmentDtos[i].CategoryDtos = categories; var catId = categories[j].Id; companies = _repo.GetCompaniesWithCatId(catId); for (int k = 0; k < companies.Count(); k++) { companyVM.DepartmentDtos[i].CategoryDtos[j].CompanyDtos = companies; } } } return(PartialView(companyVM)); }
public IActionResult Company(CompanyVM model) { //Validate model //save model var company = (Company)model; model.UserId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)); bool success = _companyRepository.Upsert(ref company); if (success) { //send a thank you signup email //send email to user var msg = ""; var greeting = $"Hi {model.ContactFirstName},"; ((EmailSender)_emailSender).SendEmailAsync(User.Identity.Name, "Welcome to Crowd Order" , msg, "Explore Exclusive Rates", "https://www.crowdorder.co.uk", greeting, EmailSender.EmailTemplate.Welcome); if (model.ReturnUrl != "/") { return(Redirect(model.ReturnUrl)); } return(RedirectToAction("Index")); } return(View()); }
// GET: CompanyController/Edit/5 public async Task <ActionResult> Edit(int id) { var currentUser = await _UserManager.GetUserAsync(User); UserRoles currentUserRoles = await _UserManager.GetUserRolesAsync(currentUser); var currentEmployee = await _UnitOfWork.Employees.FindAsync(x => x.Id.Equals(currentUser.Id)); bool roleAllowsEditCompanyData = ((currentUserRoles & UserRoles.AppAdministrator) == UserRoles.AppAdministrator) || (((currentUserRoles & UserRoles.CompanyAdministrator) == UserRoles.CompanyAdministrator) && currentEmployee?.CompanyId != id); if (!roleAllowsEditCompanyData) { _CompanyControllerLogger.LogWarning($"User {currentUser.UserName} was forbidden to browse companies"); ModelState.AddModelError("", _MessageLocalizer["Your not allowed to show the details of this company"]); return(Forbid(_MessageLocalizer["Your not allowed to show the details of this company"])); } var companyData = await _UnitOfWork.Companies.FindAsync(x => x.Id == id); if (companyData == null) { _CompanyControllerLogger.LogWarning($"Company {id} was not found"); ModelState.AddModelError("", _MessageLocalizer["Company not found"]); return(NotFound(_MessageLocalizer["Company not found"])); } CompanyVM companyVM = _Mapper.Map <CompanyVM>(companyData); ViewData["Action"] = nameof(Edit); return(View(EditionViewName, companyVM)); }
// GET: Company/Edit/5 public ActionResult Edit(int id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Company c = Service.GetById(id); CompanyVM cvm = new CompanyVM() { CompanyId = c.CompanyId, Company_Name = c.Company_Name, Company_Number = c.Company_Number, Company_Email = c.Company_Email, Company_Description = c.Company_Description, Company_Website = c.Company_Website, Company_Logo = c.Company_Logo, NumberOfEmployees = c.NumberOfEmployees, Company_Address = c.Company_Address }; if (c == null) { return(HttpNotFound()); } return(View(cvm)); }
public async Task <IActionResult> Index() { var model = new CompanyVM() { Company = null, Companies = db.Company.ToList(), Action = "Create", Button = "Əlavə et" }; if (_signInManager.IsSignedIn(User)) { var user = await _userManager.GetUserAsync(User); if (user.Status == "Admin") { return(View(model)); } else { return(RedirectToAction("Index", "AdminLogin")); } } else { return(RedirectToAction("Index", "AdminLogin")); } }
public CompanyVM GetByIdCompany(int id) { try { tblCompany company = _companyRepository.GetById(id); CompanyVM _CompanyVM = new CompanyVM(); _CompanyVM.Address = company.Address; _CompanyVM.BankAccountNo = company.BankAccountNo; _CompanyVM.BankIFSCNo = company.BankIFSCNo; _CompanyVM.BankName = company.BankName; _CompanyVM.City = company.City; _CompanyVM.CompanyName = company.CompanyName; _CompanyVM.CountryId = company.CountryId; _CompanyVM.Email = company.Email; _CompanyVM.FaxNo = company.FaxNo; _CompanyVM.GSTIN = company.GSTIN; _CompanyVM.IsActive = company.IsActive; _CompanyVM.Logo = company.Logo; _CompanyVM.MobileNo = company.MobileNo; _CompanyVM.Password = company.Password; _CompanyVM.PinCode = company.PinCode; _CompanyVM.State = company.State; _CompanyVM.TelephoneNo = company.TelephoneNo; _CompanyVM.Website = company.Website; if (company.Logo != null) { _CompanyVM.LogoPath = string.Format("data:image/jpg;base64,{0}", Convert.ToBase64String(company.Logo, 0, company.Logo.Length)); } return(_CompanyVM); } catch (Exception e) { throw e; } }
public async Task <IActionResult> Edit(int?id) { if (id != null) { var model = new CompanyVM() { Company = db.Company.FirstOrDefault(c => c.id == id), Companies = db.Company.ToList(), Action = "Edit", Button = "Redaktə et" }; if (_signInManager.IsSignedIn(User)) { var user = await _userManager.GetUserAsync(User); if (user.Status == "Admin") { return(View("Index", model)); } else { return(RedirectToAction("Index", "AdminLogin")); } } else { return(RedirectToAction("Index", "AdminLogin")); } } else { return(RedirectToAction("Index")); } }
public bool UpdateCompany(CompanyVM _CompanyVM) { try { tblCompany company = _companyRepository.GetById(_CompanyVM.CompanyId); 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.Update(company); _unitOfWork.Complete(); return(true); } catch (Exception e) { throw e; } }
public ActionResult Create(CompanyVM company) { //получение пользователя var user = new VMService(TMSService).GetUser((int)Session["Id"]); company.Creator = user; //создание компании в бд var mapperForCompany = new MapperConfiguration(cfg => cfg.CreateMap <CompanyVM, CompanyDTO>()).CreateMapper(); var companyDTO = mapperForCompany.Map <CompanyVM, CompanyDTO>(company); TMSService.MakeCompany(companyDTO); //получение списка компаний var companies = new VMService(TMSService).GetListCompaniesCreatedByUserID((int)Session["Id"]); //не ну мало ли int?companyId = null; if (companies.Count() == 1) { companyId = companies[0].Id; } else if (companies.Count() == 0) { throw new Exception("Не удалось создать компанию!"); } return(RedirectToAction("Details", new { id = companyId })); }
public IActionResult InsertCompany(CompanyVM companyVM) { User currentAdmin = HttpContext.Session.Get <User>("currentUser"); Company company = new Company(); if (ModelState.IsValid) { company.CompanyName = companyVM.CompanyName; company.Overview = companyVM.Overview; company.WebSite = companyVM.WebSite; company.Location = companyVM.Location; company.SubCategoryID = companyVM.SubCatID; company.Adress = "defauladresdefauladresdefauladres"; if (company != null) { try { companyBLL.Add(company); this._logger.LogInformation($"AdminID : {currentAdmin.ID} is created CompanyID : {company.ID}."); } catch (Exception) { throw; } } } return(View("Index")); }
public async Task <DbStatusCode> SaveCompany(CompanyVM model) { try { genericRepository.Add(new CompanyModel() { Id = Guid.NewGuid(), CompanyName = model.CompanyName, CompanyDescription = model.CompanyDescription, UserId = model.UserId }); var changedVal = await unitOfWork.Commit(); if (changedVal > 0) { return(DbStatusCode.Created); } else { return(DbStatusCode.DbError); } } catch (Exception ex) { //logging an exception return(DbStatusCode.Exception); } }
public async Task <ActionResult <CompanyVM> > CreateCompany(CompanyVM companyVM) { try { if (companyVM == null) { return(BadRequest()); } // Add custom model validation error Company company = await companyRepository.GetCompanyByname(companyVM.Company); if (company != null) { ModelState.AddModelError("Name", $"Company name: {companyVM.Company.Name} already in use"); return(BadRequest(ModelState)); } await companyRepository.CreateCompany(companyVM); return(CreatedAtAction(nameof(GetCompany), new { id = companyVM.Company.Id }, companyVM)); } catch (DbUpdateException Ex) { return(StatusCode(StatusCodes.Status500InternalServerError, Ex.InnerException.Message)); } }
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 static void DeleteSuitTransaction(CompanyVM item) { using (DbContextTransaction transaction = RepositoryBase <Company> .DbContext.Database.BeginTransaction()) { try { // kiem tra User cua Company có được cấp quyền chưa Company companyItem = GetSingleById(item.Id); ApplicationUser userItem = ApplicationUserProvider.GetSingleByName(companyItem.UserName); if (userItem != null) { ApplicationUserProvider.DeleteSuit(userItem.Id, true); } // Delete Compay Delete(item.Id); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); Trace.WriteLine("Error occurred:" + ex.Message); throw; } } }
// GET: CompanyController/Details/5 public async Task <ActionResult> Details(int id) { var currentUser = await _UserManager.GetUserAsync(User); UserRoles currentUserRoles = await _UserManager.GetUserRolesAsync(currentUser); var currentEmployee = await _UnitOfWork.Employees.FindAsync(x => x.Id.Equals(currentUser.Id), includes : new System.Linq.Expressions.Expression <Func <Employee, object> >[] { e => e.Company, e => e.Manager }); bool userAuthorizedToViewDetails = currentEmployee != null || currentEmployee?.CompanyId == id || (await _UserManager.IsMemberOfOneAsync(currentUser, UserRoles.AppAdministrator)); if (!userAuthorizedToViewDetails) { _CompanyControllerLogger.LogWarning($"User {currentUser.UserName} was forbidden to browse companies"); ModelState.AddModelError("", _MessageLocalizer["Your not allowed to show the details of this company"]); return(Forbid(_MessageLocalizer["Your not allowed to show the details of this company"])); } var companyData = await _UnitOfWork.Companies.FindAsync(predicate : x => x.Id == id); if (companyData == null) { _CompanyControllerLogger.LogWarning($"Company {id} was not found"); ModelState.AddModelError("", _MessageLocalizer["Company not found"]); return(NotFound(_MessageLocalizer["Company not found"])); } CompanyVM companyVM = _Mapper.Map <CompanyVM>(companyData); if ((currentUserRoles & (UserRoles.AppAdministrator | UserRoles.CompanyAdministrator)) == 0) { companyVM.CompanyProtectedComment = _MessageLocalizer["Hidden"]; } return(View(companyVM)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return(View(model)); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: { ApplicationUser user = await UserManager.FindAsync(model.Email, model.Password); Session["UserId"] = user.Id; var associatedCompanyList = db1.UserCompanies.Where(x => x.UserId == user.Id).Include(x => x.Company).Select(y => new { CompanyId = y.Company.Id, CompanyName = y.Company.Name, YearId = y.Company.currentFinYear_id, y.is_default }).ToList(); List <CompanyVM> companyList = new List <CompanyVM>(); foreach (var associatedCompany in associatedCompanyList) { CompanyVM company = new CompanyVM(); company.CompanyId = associatedCompany.CompanyId; company.CompanyName = associatedCompany.CompanyName; company.IsDefault = associatedCompany.is_default; company.YearId = associatedCompany.YearId; if (associatedCompany.is_default == true) { Session["CompanyID"] = associatedCompany.CompanyId; Session["CompanyName"] = associatedCompany.CompanyName; Session["FinancialYearID"] = associatedCompany.YearId; } companyList.Add(company); } Session["companyListAssociatedWithUser"] = companyList; return(RedirectToLocal(returnUrl)); } case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public async Task <CompanyVM> GetCompany(int id) { CompanyVM companyVM = new CompanyVM(); companyVM.Company = await appDbContext.Companys.FirstOrDefaultAsync(e => e.Id == id); return(companyVM); }
//получить детальную информацию о пользователе (тестовый метод) public ActionResult UserInfo(int id) { //получить пользователя UserDTO userDto = TMSService.GetUser(id); var mapper = new MapperConfiguration(cfg => cfg.CreateMap <UserDTO, UserVM>()).CreateMapper(); var user = mapper.Map <UserDTO, UserVM>(userDto); IEnumerable <CompanyDTO> companiesDTO = TMSService.GetCompanies(); var mapperComp = new MapperConfiguration(cfg => cfg.CreateMap <CompanyDTO, CompanyVM>()).CreateMapper(); var companiesEmployee = mapper.Map <IEnumerable <CompanyDTO>, List <CompanyVM> >(companiesDTO); CompanyVM employedComp = null; List <CompanyVM> createdComp = new List <CompanyVM>(); //компании в которых сотрудник устроен for (int i = 0; i < companiesEmployee.Count; i++) { bool employed = false; for (int j = 0; j < companiesEmployee[i].Users.Count; j++) { if (companiesEmployee[i].Users[j].Id == user.Id) { employed = true; } } if (employed) { employedComp = companiesEmployee[i]; } } // компании которые он создал for (int i = 0; i < companiesEmployee.Count; i++) { bool created = false; for (int j = 0; j < companiesEmployee[i].Users.Count; j++) { if (companiesEmployee[i].Creator.Id == user.Id) { created = true; } } if (created) { CompanyVM company = new CompanyVM { Id = companiesEmployee[i].Id, Creator = companiesEmployee[i].Creator, Name = companiesEmployee[i].Name, Users = companiesEmployee[i].Users }; createdComp.Add(company); } } ViewBag.createdComp = createdComp; ViewBag.employedComp = employedComp; return(View("Index", user)); }
public async Task <CompanyVM> CreateCompany(CompanyVM companyVM) { var result = await appDbContext.Companys.AddAsync(companyVM.Company); await appDbContext.SaveChangesAsync(); companyVM.Company = result.Entity; return(companyVM); }
public static void Update(CompanyVM item) { Company dbItem = RepositoryBase <Company> .GetSingleById(item.Id); dbItem.UpdateCompany(item); RepositoryBase <Company> .Update(dbItem); RepositoryBase <Company> .SaveChanges(); }
public ActionResult OrganizationDetail(string id_encrypted) { CompanyVM companymodel = new CompanyVM(); CompanyModel companyModel = new CompanyModel(); companyModel = companyBusiness.GetCompanyDetail(id_encrypted.Decrypt()); AutoMapper.Mapper.Map(companyModel, companymodel); // companymodel.CreatedBy=userBusiness.getuse return(View(companymodel)); }
IEnumerable <CompanyVM> GetData(string ID) { CompanyVM item = Mapper.Map <CompanyVM>(CompanyProvider.GetSingleById(ID)); List <CompanyVM> ItemList = new List <CompanyVM>(); if (item != null) { ItemList.Add(item); } return(ItemList); }
public ActionResult Create() { // pogledu proslijedi "dummy" model - id 0, a placeID prvi abecedno var model = new CompanyVM { IDCompany = 0, PlaceID = _repository.GetAllPlaces().OrderBy(p => p.Name).FirstOrDefault().IDPlace }; ViewBag.allPlaces = getAllPlaces(); return(View(model)); }
private Company getCompanyFromViewModel(CompanyVM vm) { return(new Company { IDCompany = vm.IDCompany, CompanyCode = vm.CompanyCode, Name = vm.CompanyName, Address = vm.Address, PostalCode = vm.PostalCode, PlaceID = vm.PlaceID }); }
public ActionResult GetLstUser(CompanyVM modelSearch, int?page) { int totalRecord = 0; var model = _userRepository.GetLst(modelSearch.search.GetEntity(), page, NumberRecord, out totalRecord); return(Json(new { view = RenderRazorViewToString(ControllerContext, "LstView", model) })); //return PartialView(model); }
public ActionResult AddOrEditCompany(CompanyVM _companyVM, HttpPostedFileBase file) { ViewBag.Country = _CompanySerivce.CountryList(); if (ModelState.IsValid) { bool status = false; var id = _CompanySerivce.IsExist(); if (file != null) { byte[] bytes; using (BinaryReader br = new BinaryReader(file.InputStream)) { bytes = br.ReadBytes((Int32)file.InputStream.Length); } _companyVM.Logo = bytes; string FileName = string.Empty, FilePath = string.Empty; FileName = System.IO.Path.GetFileName(file.FileName); FilePath = System.IO.Path.Combine(Server.MapPath("~/ImagesData/"), FileName); file.SaveAs(FilePath); _companyVM.LogoPath = "~/ImagesData/" + FileName; } if (id == 0) { status = _CompanySerivce.CreateCompany(_companyVM); if (status) { return(Json(new { success = true, message = "Created Successfully...!" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "Error...!" }, JsonRequestBehavior.AllowGet)); } } else { _companyVM.CompanyId = id; status = _CompanySerivce.UpdateCompany(_companyVM); if (status) { return(Json(new { success = true, message = "Updated Successfully...!" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "Error...!" }, JsonRequestBehavior.AllowGet)); } } } else { return(View(_companyVM)); } }
private void UpdateCompanyModel(CompanyVM vm, Company company, IEnumerable <CompanyBusinessLine> businessLines, IEnumerable <Affiliate> affiliates, IEnumerable <Contact> contacts) { company.Name = vm.Name; company.Site = vm.Site; company.Information = vm.Information; company.BusinessLines = RightJoin(company.BusinessLines, businessLines, new BusinessLineComparer()); company.Affiliates = RightJoin(company.Affiliates, affiliates, new AffiliateComparer()); company.Contacts = RightJoin(company.Contacts, contacts, new ContactComparer()); }
public ActionResult Create(CompanyVM vm) { if (ModelState.IsValid) { Company entity = getCompanyFromViewModel(vm); _repository.InsertOrUpdateCompany(entity); return(RedirectToAction("ViewAll")); } else { ViewBag.allPlaces = getAllPlaces(); return(View(vm)); } }
public ActionResult Details(int id) { CompanyVM company = new CompanyVM(); try { company = _service.GetById(id); } catch (Exception ex) { throw; } return(View(company)); }
// GET: Company/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CompanyVM company = _service.GetById(id); if (company == null) { return(HttpNotFound()); } return(View(company)); }