public static dynamic ToUpdateCompanyCommand(this UpdateCompanyViewModel company) { if (company == null) { return(null); } return(new { CompanyId = company.Id, company.ParentId, company.Name, company.Website, company.LogoBase64, company.Logo, company.SupportSiteUrl, company.ControlPanelSiteUrl, company.Email, company.PhoneNumber, company.StreetAddress, company.City, company.ZipCode, company.State, company.Country, company.BrandColorPrimary, company.BrandColorSecondary, company.BrandColorText, company.Domains, company.CatalogId }); }
public static Company ToCompany(this UpdateCompanyViewModel model) { return(new Company { Id = model.Id, Name = model.Name, TimezoneId = model.TimeZoneId }); }
public UpdateCompanyViewModel GetCompanyForUpdateById(short CompanyRowID) { try { UpdateCompanyViewModel model = new UpdateCompanyViewModel(); var entity = db.MasterCompanies.Find(CompanyRowID); if (entity != null) { model.CompanyRowID = entity.CompanyRowID; model.CompanyName = entity.CompanyName; model.CompanyAddress = entity.CompanyAddress; model.CountryRowID = entity.CountryRowID; model.StateRowID = entity.StateRowID; model.DistrictRowID = entity.DistrictRowID; model.LocationRowID = entity.LocationRowID; model.GeneralEmail = entity.GeneralEmail; model.MobileNo = entity.MobileNo; model.PhoneNo = entity.PhoneNo; model.FaxNo = entity.FaxNo; model.BillingEmail = entity.BillingEmail; model.BillingDName = entity.BillingDName; model.InitiationEmail = entity.InitiationEmail; model.InitiationDisplay = entity.InitiationDName; model.InsuffDName = entity.InsuffDName; model.InsuffEmail = entity.InsuffEmail; model.ReportEmail = entity.ReportEmail; model.ReportDName = entity.ReportDName; model.MISDName = entity.MISDName; model.MISEmail = entity.MISEmail; model.OtherDName = entity.OtherDName; model.OtherEmail = entity.OtherEmail; model.BillingEmail = entity.BillingEmail; model.SMTPServer = entity.SMTPServer; model.SMTPPort = entity.SMTPPort; model.SMTPUserName = entity.SMTPUserName; //model.SMTPPassword = entity.SMTPPassword; model.EnableSsl = Convert.ToBoolean(entity.EnableSsl); } else { throw new Exception("Invalid Id!"); } return(model); } catch (Exception) { throw; } }
public ActionResult Update(UpdateCompanyViewModel model) { var company = _companyService.Get(model.Id); if (company != null && company.Id != model.Id) { ModelState.AddModelError("Name", "Company's name already registered"); return(View(model)); } _companyService.Update(model.ToCompany()); return(RedirectToAction("Index", "Companies")); }
public ActionResult Edit(int id, UpdateCompanyViewModel vm) { DataManager dm = new DataManager(); try { dm.UpdateCompany(vm); return(RedirectToAction("Index")); } catch { return(View()); } }
public async Task <IHttpActionResult> AddCustomSecureControlPanel(CustomSecureControlPanelModel model) { var CompanyEntity = await _customSecureControlPanelService.CreateCustommeSecureControlPanel(model); var UpdateCompany = new UpdateCompanyViewModel() { Id = CompanyEntity.Id, ParentId = CompanyEntity.ParentId, Name = CompanyEntity.Name, Website = CompanyEntity.Website, LogoBase64 = CompanyEntity.LogoUrl, SupportSiteUrl = CompanyEntity.SupportSiteUrl, ControlPanelSiteUrl = CompanyEntity.ControlPanelSiteUrl, Email = CompanyEntity.Email, PhoneNumber = CompanyEntity.PhoneNumber, StreetAddress = CompanyEntity.StreetAddress, City = CompanyEntity.City, ZipCode = CompanyEntity.ZipCode, State = CompanyEntity.State, Country = CompanyEntity.Country, BrandColorPrimary = CompanyEntity.BrandColorPrimary, BrandColorSecondary = CompanyEntity.BrandColorSecondary, BrandColorText = CompanyEntity.BrandColorText, Domains = CompanyEntity.Domains.AsEnumerable().Select(x => new CreateDomainViewModel { Name = x.Name, IsPrimary = x.IsPrimary }).ToList() }; var updateCompanyQueue = CompanyServiceConstants.QueueUpdateCompany; await _messageBroker.GetSendEndpoint(updateCompanyQueue) .Send <IUpdateCompanyCommand>( UpdateCompany.ToUpdateCompanyCommand() ); var sendEmailQueue = NotificationServiceConstants.QueueSendEmailNotification; await _messageBroker.GetSendEndpoint(sendEmailQueue).Send <ISendEmailCommand>( new { CustomSecureCompanyId = model.Id, CompanyId = model.Id, To = _cloudPlusApiSettings.CloudPlusSupportGroupEmail, EmailTemplateType = EmailTemplateType.CustomSecureControlPanelActivation, }); return(Ok()); }
public void UpdateCompany(UpdateCompanyViewModel model) { try { if (model != null) { db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).CompanyName = model.CompanyName; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).CompanyAddress = model.CompanyAddress; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).LocationRowID = model.LocationRowID; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).CountryRowID = model.CountryRowID; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).StateRowID = model.StateRowID; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).DistrictRowID = model.DistrictRowID; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).GeneralEmail = model.GeneralEmail; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).MobileNo = model.MobileNo; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).PhoneNo = model.PhoneNo; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).FaxNo = model.FaxNo; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).BillingEmail = model.BillingEmail; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).BillingDName = model.BillingDName; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).InitiationEmail = model.InitiationEmail; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).InitiationDName = model.InitiationDisplay; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).InsuffDName = model.InsuffDName; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).InsuffEmail = model.InsuffEmail; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).ReportEmail = model.ReportEmail; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).ReportDName = model.ReportDName; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).MISDName = model.MISDName; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).MISEmail = model.MISEmail; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).OtherDName = model.OtherDName; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).OtherEmail = model.OtherEmail; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).BillingEmail = model.BillingEmail; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).SMTPServer = model.SMTPServer; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).SMTPPort = model.SMTPPort; db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).SMTPUserName = model.SMTPUserName; if (!string.IsNullOrEmpty(model.SMTPPassword)) { db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).SMTPPassword = model.SMTPPassword; } db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).EnableSsl = Convert.ToByte(model.EnableSsl); db.MasterCompanies.Single(c => c.CompanyRowID == model.CompanyRowID).CompanyLogo = model.CmpLogo; } } catch (Exception) { throw; } }
public async Task <IHttpActionResult> UpdateCompany(UpdateCompanyViewModel model) { if (User.CompanyId() == model.Id) { model.CatalogId = null; } model.Logo = _imageHelper.SaveCompanyLogo(model.LogoBase64); model.ParentId = User.CompanyId(); var updateCompanyQueue = CompanyServiceConstants.QueueUpdateCompany; await _messageBroker.GetSendEndpoint(updateCompanyQueue) .Send <IUpdateCompanyCommand>( model.ToUpdateCompanyCommand() ); return(Ok()); }
public ActionResult Update(int id) { var company = _companyService.Get(id); if (company == null) { return(RedirectToAction("Index")); } var model = new UpdateCompanyViewModel { Id = id, Name = company.Name, TimeZoneId = company.TimezoneId }; return(View(model)); }
public IActionResult UpdateCompany(Guid?alumniprofileId) { var alumniprofile = this._context.AlumniProfiles.FirstOrDefault(a => a.Id == alumniprofileId); if (alumniprofile != null) { var model = new UpdateCompanyViewModel() { AlumniProfileId = alumniprofile.Id, Description = alumniprofile.Description, Company = alumniprofile.Company, Position = alumniprofile.Position, Location = alumniprofile.Location, FromDate = alumniprofile.FromDate, ToDate = alumniprofile.ToDate }; return(View(model)); } return(RedirectToAction("Create")); }
public IActionResult UpdateCompany(UpdateCompanyViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var alumniprofile = this._context.AlumniProfiles.FirstOrDefault(a => a.Id == model.AlumniProfileId); if (alumniprofile != null) { alumniprofile.Company = model.Company; alumniprofile.Description = model.Description; alumniprofile.FromDate = model.FromDate; alumniprofile.ToDate = model.ToDate; alumniprofile.Position = model.Position; alumniprofile.Location = model.Location; this._context.AlumniProfiles.Update(alumniprofile); this._context.SaveChanges(); } return(RedirectToAction("Index")); }
public async Task <IActionResult> UpdateCompany([FromForm] UpdateCompanyViewModel companyModel) { if (companyModel == null) { return(BadRequest("Object of type company is null")); } if (!ModelState.IsValid) { return(View(companyModel)); } else { try { var company = await companyService.GetCompanyById(companyModel.Id); if (company == null) { return(NotFound($"Company with id {companyModel.Id} not find")); } else { var updatedCompany = UpdateCompanyToCompanyDTOMapper.Instance.Map(companyModel); await companyService.UpdateCompany(updatedCompany); return(RedirectToAction(nameof(GetAllCompanies))); } } catch (DbUpdateException ex) { logger.LogError($"Unable to update company becuase of {ex.Message}"); ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists, " + "see your system administrator."); return(View(companyModel)); } } }
//update Company public bool UpdateCompany(UpdateCompanyViewModel vm) { connection(); SqlCommand com = new SqlCommand("UPDATE Companies SET CompanyName=@CompanyName WHERE Id=@Id", _con); com.CommandType = CommandType.Text; com.Parameters.AddWithValue("@Id", vm.Id); com.Parameters.AddWithValue("@CompanyName", vm.CompanyName); _con.Open(); int i = com.ExecuteNonQuery(); _con.Close(); if (i >= 1) { return(true); } else { return(false); } }
public async Task <IActionResult> UpdateCompanyAsync(UpdateCompanyViewModel model) { try { CompanyDto company = new CompanyDto { Id = model.Company.Id, Title = model.Company.Title, Address = model.Company.Address }; await companyService.UpdateAsync(company); return(RedirectToAction("CompaniesList", "Company")); } catch (Exception ex) { ErrorViewModel errorModel = new ErrorViewModel(); errorModel.ErrorMessage = ex.Message.ToString(); return(View("Views/Shared/Error.cshtml", errorModel)); } }
public async Task <IActionResult> Update([FromBody] UpdateCompanyViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { string strRuta = _config["AvatarFiles"]; Company company = await _context.Companies.Include(x => x.CompanySectors).Include(x => x.SecurityRoles).ThenInclude(x => x.SecurityRoleScreens).Include(x => x.SecurityRoles).ThenInclude(x => x.SecurityRoleActions).Include(x => x.ConfigScreen).ThenInclude(x => x.SecurityActions).Include(x => x.ConfigScreen).ThenInclude(x => x.ConfigScreenFields).Where(x => x.Id == model.Id).FirstOrDefaultAsync(); var listRoles = company.SecurityRoles; if (company == null) { return(BadRequest("Compania inexistente")); } //Actualizo la compania company.Name = model.Name; company.ContactName = model.ContactName; company.ContactLastName = model.ContactLastName; company.InitialDate = model.InitialDate; company.Email = model.Email; company.Phone = model.Phone; company.Website = model.Website; company.Address = model.Address; company.Postal = model.Postal; company.City = model.City; company.State = model.State; company.Country = model.Country; company.Schedule = model.Schedule; company.Comment = model.Comment; ////Guardo el avatar if (!(string.IsNullOrEmpty(model.LogoName)) && (!string.IsNullOrEmpty(model.Logo))) { strRuta = strRuta + "//" + company.Id.ToString() + "//" + model.LogoName; System.IO.FileInfo file = new System.IO.FileInfo(strRuta); file.Directory.Create(); System.IO.File.WriteAllBytes(strRuta, Convert.FromBase64String(model.Logo.Substring(model.Logo.LastIndexOf(',') + 1))); company.Logo = strRuta; } //Sectores var sectorToBeAdded = model.CompanySectors.Where(a => company.CompanySectors.All( b => b.SectorId != a.SectorId)); var sectorToBeDeleted = company.CompanySectors.Where(a => model.CompanySectors.All( b => b.SectorId != a.SectorId)); foreach (var sector in sectorToBeDeleted) { company.CompanySectors.Remove(sector); } foreach (var sector in sectorToBeAdded) { company.CompanySectors.Add(sector); } //Screens //Solo vienen las activas var screenToBeAdded = model.ConfigScreens.Where(a => company.ConfigScreen.All( b => b.SystemScreenId != a.SystemScreenId)); var screenToBeDeleted = company.ConfigScreen.Where(a => model.ConfigScreens.All( b => b.SystemScreenId != a.SystemScreenId)); //Si no se dan de alta o se eliminan, los actualizo //son todos los que no se graban + los que no se eliminan List <ConfigScreen> screenNotbeUpdated = new List <ConfigScreen>(); List <ConfigScreen> screenEnabled = new List <ConfigScreen>(); screenNotbeUpdated.AddRange(screenToBeAdded); screenNotbeUpdated.AddRange(screenToBeDeleted); var screenToBeUpdated = model.ConfigScreens.Where(a => screenNotbeUpdated.All( b => b.SystemScreenId != a.SystemScreenId)); screenEnabled.AddRange(screenToBeAdded); screenEnabled.AddRange(screenToBeUpdated); //Elimino las pantallas del paso 2 foreach (var screenDtl in screenToBeDeleted.ToList()) { //Borro los childs ConfigScreen configScreen = company.ConfigScreen.Where(x => x.SystemScreenId == screenDtl.SystemScreenId).FirstOrDefault(); //Seteo las dependencias var securityactionsToDelete = configScreen.SecurityActions; var configScreenFieldToDelete = configScreen.ConfigScreenFields; //Borro las acciones foreach (var action in securityactionsToDelete.ToList()) { configScreen.SecurityActions.Remove(action); } //Borro los atributos foreach (var attr in configScreenFieldToDelete.ToList()) { configScreen.ConfigScreenFields.Remove(attr); } var listRolesToDelete = listRoles; //Borro las pantallas de los roles foreach (var item in listRolesToDelete.ToList()) { var listRolesActionToDelete = item.SecurityRoleActions.Where(x => x.SecurityAction.ConfigScreen.SystemScreenId == screenDtl.SystemScreenId).ToList(); foreach (var action in listRolesActionToDelete) { item.SecurityRoleActions.Remove(action); } var listRolesScreenToDelete = item.SecurityRoleScreens.Where(x => x.ConfigScreen.SystemScreenId == screenDtl.SystemScreenId).ToList(); foreach (var screen in listRolesScreenToDelete) { item.SecurityRoleScreens.Remove(screen); } } company.ConfigScreen.Remove(configScreen); } //Modifico foreach (var screen in company.ConfigScreen) { ConfigScreen configScreen = screenToBeUpdated.Where(x => x.SystemScreenId == screen.SystemScreenId).FirstOrDefault(); if (configScreen != null) { screen.Description = configScreen.Description; screen.Enabled = configScreen.Enabled; screen.Icon = configScreen.Icon; screen.Orden = configScreen.Orden; } //Actualizo los fields if (configScreen.ConfigScreenFields != null) { foreach (var item2 in configScreen.ConfigScreenFields) { bool existField = false; foreach (var item1 in screen.ConfigScreenFields) { //Me fijo si esta creado, si esta lo actualizo if (item1.SystemScreenFieldId == item2.SystemScreenFieldId) { item1.Enabled = item2.Enabled; item1.DefaultValue = item2.DefaultValue; item1.Orden = item2.Orden; item1.FieldName = item2.FieldName; item1.Name = item2.Name; item1.Required = item2.Required; item1.Visible = item2.Visible; existField = true; break; } } //Sino existe lo creo if (!existField) { ConfigScreenField configScreenField = new ConfigScreenField { Enabled = item2.Enabled, DefaultValue = item2.DefaultValue, Orden = item2.Orden, FieldName = item2.FieldName, Name = item2.Name, Required = item2.Required, Visible = item2.Visible, ConfigScreenId = item2.ConfigScreenId, SystemScreenFieldId = item2.SystemScreenFieldId }; screen.ConfigScreenFields.Add(configScreenField); } } } //Actualizo las acciones if (configScreen.SecurityActions != null) { foreach (var item2 in configScreen.SecurityActions) { bool existAction = false; foreach (var item1 in screen.SecurityActions) { if (item1.SystemActionId == item2.SystemActionId) { item1.Enabled = item2.Enabled; item1.Description = item2.Description; existAction = true; break; } } //Sino existe lo creo if (!existAction) { SecurityAction securityAction = new SecurityAction { Enabled = item2.Enabled, Description = item2.Description, ConfigScreenId = item2.ConfigScreenId, SystemActionId = item2.SystemActionId }; screen.SecurityActions.Add(securityAction); } } } } //Agrego foreach (var screenAdd in screenToBeAdded.ToList()) { ConfigScreen configScreenAdd = new ConfigScreen { CompanyId = model.Id, Description = screenAdd.Description, Enabled = screenAdd.Enabled, Orden = screenAdd.Orden, Icon = screenAdd.Icon, SystemScreenId = screenAdd.SystemScreenId }; //tambien agrego los atributos //Dentro de las pantallas agrego los Atributos if (screenAdd.ConfigScreenFields != null) { configScreenAdd.ConfigScreenFields = new List <ConfigScreenField>(); foreach (var field in screenAdd.ConfigScreenFields) { ConfigScreenField configScreenField = new ConfigScreenField { ConfigScreenId = screenAdd.Id, Name = field.Name, Required = field.Required, Visible = field.Visible, DefaultValue = field.DefaultValue, Orden = field.Orden, Enabled = field.Enabled, FieldName = field.FieldName, SystemScreenFieldId = field.SystemScreenFieldId, }; configScreenAdd.ConfigScreenFields.Add(configScreenField); } } //Dentro de las pantallas agrego las Acciones if (screenAdd.SecurityActions != null) { configScreenAdd.SecurityActions = new List <SecurityAction>(); foreach (var action in screenAdd.SecurityActions) { SecurityAction securityAction = new SecurityAction { ConfigScreenId = screenAdd.Id, Description = action.Description, Enabled = action.Enabled, SystemActionId = action.SystemActionId, }; configScreenAdd.SecurityActions.Add(securityAction); } } company.ConfigScreen.Add(configScreenAdd); } _context.Entry(company).State = EntityState.Modified; await _context.SaveChangesAsync(); //SecurityRoles //Vienen todos los roles foreach (var modelRol in model.SecurityRoles.ToList()) { //Paso 5 SecurityRole securityRole = company.SecurityRoles.Where(x => x.SystemRoleId == modelRol.SystemRoleId).FirstOrDefault(); if (securityRole != null) { securityRole.Description = modelRol.Description; securityRole.Name = modelRol.Name; securityRole.Enabled = modelRol.Enabled; var screenRolToBeAdded = modelRol.SecurityRoleScreens.Where(a => securityRole.SecurityRoleScreens.All( b => b.ConfigScreen.SystemScreenId != a.SystemScreenId)); var screenRolToBeDeleted = securityRole.SecurityRoleScreens.Where(a => modelRol.SecurityRoleScreens.All( b => b.SystemScreenId != a.ConfigScreen.SystemScreenId)); var actionRolToBeAdded = modelRol.SecurityRoleActions.Where(a => securityRole.SecurityRoleActions.All( b => b.SecurityAction.SystemActionId != a.SystemActionId)); var actionRolToBeDeleted = securityRole.SecurityRoleActions.Where(a => modelRol.SecurityRoleActions.All( b => b.SystemActionId != a.SecurityAction.SystemActionId)); //SCREENS foreach (var item in screenRolToBeDeleted.ToList()) { securityRole.SecurityRoleScreens.Remove(item); } foreach (var item2 in screenRolToBeAdded.ToList()) { SecurityRoleScreen securityRoleScreen = new SecurityRoleScreen { SecurityRoleId = item2.SystemRoleId, ConfigScreenId = company.ConfigScreen.Where(x => x.SystemScreenId == item2.SystemScreenId).Select(x => x.Id).FirstOrDefault() }; securityRole.SecurityRoleScreens.Add(securityRoleScreen); } //ACCIONES foreach (var item in actionRolToBeDeleted.ToList()) { securityRole.SecurityRoleActions.Remove(item); } foreach (var item2 in actionRolToBeAdded.ToList()) { var configScreen = company.ConfigScreen.Where(x => x.SystemScreenId == item2.SystemScreenId).FirstOrDefault(); if (configScreen != null) { foreach (var action in configScreen.SecurityActions) { if (item2.SystemActionId == action.SystemActionId) { SecurityRoleAction securityRoleAction = new SecurityRoleAction { SecurityRoleId = item2.SystemRoleId }; securityRoleAction.SecurityActionId = action.Id; securityRole.SecurityRoleActions.Add(securityRoleAction); break; } } } } } } _context.Entry(company).State = EntityState.Modified; await _context.SaveChangesAsync(); } catch (Exception ex) { return(BadRequest()); } return(Ok()); }