public bool EditCompany(SA_Company News) { // News.CreatedDate = DateTime.Now; SA_Company EditNews = _context.SA_Company.Where(Cat => Cat.id == News.id).FirstOrDefault(); EditNews.Address = News.Address; EditNews.Category = News.Category; EditNews.CEO = News.CEO; EditNews.CIN = News.CIN; EditNews.Meta = News.Meta; EditNews.MetaDescription = News.MetaDescription; EditNews.Description = News.Description; EditNews.Logo = News.Logo; EditNews.Name = News.Name; EditNews.NOE = News.NOE; EditNews.phoneNo = News.phoneNo; EditNews.website = News.website; EditNews.EmailId = News.EmailId; EditNews.fax = News.fax; EditNews.RegDate = News.RegDate; _context.Entry(EditNews).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public async Task <bool> AddCustomer(SA_Customer User) { // User.CreatedDate = DateTime.Now; _context.SA_Customers.Add(User); int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public bool EditChemContent(SA_ChemContent News) { SA_ChemContent EditNews = _context.SA_ChemContent.Where(Cat => Cat.id == News.id).FirstOrDefault(); EditNews.Title = News.Title; EditNews.Description = News.Description; _context.Entry(EditNews).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public bool EditJob(SA_Job News) { // News.CreatedDate = DateTime.Now; SA_Job EditNews = _context.SA_Job.Where(Cat => Cat.id == News.id).FirstOrDefault(); EditNews.JobName = News.JobName; EditNews.JobDiscription = News.JobDiscription; EditNews.Meta = News.Meta; EditNews.MetaDiscription = News.MetaDiscription; _context.Entry(EditNews).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public bool EditCMS(SA_CMS CMS) { // CMS.CreatedDate = DateTime.Now; SA_CMS EditCMS = _context.SA_CMS.Where(Cat => Cat.id == CMS.id).FirstOrDefault(); EditCMS.CMSName = CMS.CMSName; EditCMS.CMSDiscription = CMS.CMSDiscription; EditCMS.Meta = CMS.Meta; EditCMS.MetaDiscription = CMS.MetaDiscription; EditCMS.Product = CMS.Product; _context.Entry(EditCMS).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public bool EditSlider(SA_Slider News) { // News.CreatedDate = DateTime.Now; SA_Slider EditNews = _context.SA_Slider.Where(Cat => Cat.id == News.id).FirstOrDefault(); EditNews.Title = News.Title; EditNews.Category = News.Category; EditNews.Discription = News.Discription; EditNews.Meta = News.Meta; EditNews.MetaDiscription = News.MetaDiscription; _context.Entry(EditNews).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public void AddLeadDetails(Lead_Master Lead) { _context.Entry(Lead).State = EntityState.Modified; // Role.ModeifiedDate = DateTime.Now; int x = _context.SaveChanges(); // return x == 0 ? false : true; }
public ActionResult SaveCompanyProduct(SA_Product model) { if (!ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChemAnalystContext _context = new ChemAnalystContext(); var companyProductInDb = _context.SA_Product.SingleOrDefault(p => p.id == model.id); if (companyProductInDb == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } companyProductInDb.ProductName = model.ProductName; companyProductInDb.ProductDiscription = model.ProductDiscription; companyProductInDb.Meta = model.Meta; companyProductInDb.MetaDiscription = model.MetaDiscription; companyProductInDb.status = model.status; companyProductInDb.CreatedTime = model.CreatedTime; companyProductInDb.ProductImg = model.ProductImg; companyProductInDb.Category = model.Category; _context.SaveChanges(); return(RedirectToAction("AllCompanyProducts")); }
public ActionResult SaveCompanyAndProductRelation(CompanyProfAndCompanyProductRelationFormViewModel viewModel) { //if (!ModelState.IsValid) // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); ChemAnalystContext _context = new ChemAnalystContext(); foreach (var item in viewModel.CompanyProduct) { if (item.IsSelected) { var checkForSameCompany = _context.CompanyAndProductRelations.Where(w => w.SA_CompanyId == viewModel.CompanyProfId && w.SA_ProductId == item.id).FirstOrDefault(); if (checkForSameCompany != null) { TempData["Message"] = "This compnay already exist with same product."; } else { CompanyAndProductRelation companyAndProductRelation = new CompanyAndProductRelation(); companyAndProductRelation.SA_CompanyId = viewModel.CompanyProfId; companyAndProductRelation.SA_ProductId = item.id; _context.CompanyAndProductRelations.Add(companyAndProductRelation); } } } _context.SaveChanges(); //TEMP REDIRECT. return(RedirectToAction("AllComAndProductRelationRecords")); }
public bool EditProduct(SA_Product Product) { // Product.CreatedDate = DateTime.Now; SA_Product EditProduct = _context.SA_Product.Where(Cat => Cat.id == Product.id).FirstOrDefault(); EditProduct.ProductName = Product.ProductName; EditProduct.ProductDiscription = Product.ProductDiscription; EditProduct.Meta = Product.Meta; EditProduct.MetaDiscription = Product.MetaDiscription; EditProduct.Category = Product.Category; if (Product.ProductImg != null) { EditProduct.ProductImg = Product.ProductName; } _context.Entry(EditProduct).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public bool EditCategory(SA_Category Category) { // Category.CreatedDate = DateTime.Now; SA_Category EditCategory = _context.SA_Category.Where(Cat => Cat.id == Category.id).FirstOrDefault(); EditCategory.CategoryName = Category.CategoryName; EditCategory.CategoryDiscription = Category.CategoryDiscription; EditCategory.Meta = Category.Meta; EditCategory.MetaDiscription = Category.MetaDiscription; //EditCategory.Product = Category.Product; if (Category.CategoryImg != null) { EditCategory.CategoryImg = Category.CategoryImg; } _context.Entry(EditCategory).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public bool EditCommentary(SA_Commentary News) { SA_Commentary EditNews = _context.SA_Commentary.Where(Cat => Cat.id == News.id).FirstOrDefault(); EditNews.Title = News.Title; EditNews.Description = News.Description; EditNews.Meta = News.Meta; EditNews.MetaDescription = News.MetaDescription; EditNews.IsActive = News.IsActive; EditNews.IsDelete = News.IsDelete; EditNews.Product = News.Product; EditNews.ImgPath = News.ImgPath; EditNews.CreatedTime = News.CreatedTime; _context.Entry(EditNews).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public ActionResult SaveCountry(SA_Country Country) { if (Country.id == 0) { var check = _context.SA_Country.Where(w => w.CountryName == Country.CountryName).FirstOrDefault(); if (check != null) { TempData["Message"] = "This country is already exist!"; return(RedirectToAction("AddCountry")); } else { SA_Country Obj = new SA_Country(); Obj.CountryName = Country.CountryName; Obj.Active = true; _context.SA_Country.Add(Obj); _context.SaveChanges(); } } else { var Obj = _context.SA_Country.Where(w => w.id == Country.id).FirstOrDefault(); Obj.CountryName = Country.CountryName; _context.SaveChanges(); return(RedirectToAction("ShowCountryList")); } return(RedirectToAction("ShowCountryList")); }
public bool EditDeals(SA_Deals Deals) { // Deals.CreatedDate = DateTime.Now; SA_Deals EditDeals = _context.SA_Deals.Where(Cat => Cat.id == Deals.id).FirstOrDefault(); EditDeals.DealsName = Deals.DealsName; EditDeals.DealsDiscription = Deals.DealsDiscription; EditDeals.URL = Deals.URL; EditDeals.MetaDiscription = Deals.MetaDiscription; EditDeals.MetaTitle = Deals.MetaTitle; EditDeals.Keywords = Deals.Keywords; EditDeals.Product = Deals.Product; EditDeals.CreatedTime = Deals.CreatedTime; if (Deals.DealsImg != null) { EditDeals.DealsImg = Deals.DealsImg; } _context.Entry(EditDeals).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public ActionResult SaveCompanyProf(SA_Company model) { if (!ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChemAnalystContext _context = new ChemAnalystContext(); var companyProfInDb = _context.SA_Company.SingleOrDefault(c => c.id == model.id); if (companyProfInDb == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); file.SaveAs(path); companyProfInDb.Logo = fileName; } } companyProfInDb.Name = model.Name; companyProfInDb.Description = model.Description; //companyProfInDb.Logo = model.Logo; companyProfInDb.RegDate = Convert.ToDateTime(model.RegDate); companyProfInDb.CIN = model.CIN; companyProfInDb.Category = model.Category; companyProfInDb.Address = model.Address; companyProfInDb.NOE = model.NOE; companyProfInDb.CEO = model.CEO; companyProfInDb.Meta = model.Meta; companyProfInDb.MetaDescription = model.MetaDescription; companyProfInDb.website = model.website; companyProfInDb.phoneNo = model.phoneNo; companyProfInDb.fax = model.fax; companyProfInDb.EmailId = model.EmailId; //companyProfInDb.CreatedTime = model.CreatedTime; _context.SaveChanges(); return(RedirectToAction("AllCompanyProf")); }
public bool EditIndustry(SA_Industry News) { SA_Industry EditNews = _context.SA_Industry.Where(Cat => Cat.id == News.id).FirstOrDefault(); EditNews.Title = News.Title; EditNews.Description = News.Description; EditNews.Meta = News.Meta; EditNews.MetaDescription = News.MetaDescription; EditNews.Figot = News.Figot; EditNews.Industry = News.Industry; EditNews.format = News.format; EditNews.Pages = News.Pages; EditNews.RelatedRep = News.RelatedRep; EditNews.Tableoc = News.Tableoc; EditNews.Product = News.Product; EditNews.CategoryID = News.CategoryID; EditNews.CountryID = News.CountryID; EditNews.CreatedTime = News.CreatedTime; _context.Entry(EditNews).State = EntityState.Modified; int x = _context.SaveChanges(); return(x == 0 ? false : true); }
public ActionResult Delete(int?id) { ChemAnalystContext _context = new ChemAnalystContext(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SA_Company state = _context.SA_Company.Where(c => c.id == id).FirstOrDefault(); _context.Entry(state).State = EntityState.Deleted; int x = _context.SaveChanges(); return(RedirectToAction("AllCompanyProf")); }
// POST: Customer/SaveCustomerAndProductRelation public ActionResult SaveCustomerAndProductRelation(CustomerProductFormViewModel viewModel) { ChemAnalystContext _context = new ChemAnalystContext(); foreach (var item in viewModel.SA_Product) { if (item.IsSelected) { CustomerAndProducRelation customerAndProducRelation = new CustomerAndProducRelation(); customerAndProducRelation.Lead_MasterId = viewModel.Lead_Master.Id; customerAndProducRelation.SA_ProductId = item.id; _context.CustomerAndProducRelation.Add(customerAndProducRelation); } } _context.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult ConfirmDelete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChemAnalystContext _context = new ChemAnalystContext(); var companyProductInDb = _context.CompanyAndProductRelations.SingleOrDefault(d => d.Id == id); if (companyProductInDb == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } _context.CompanyAndProductRelations.Remove(companyProductInDb); _context.SaveChanges(); return(RedirectToAction("AllComAndProductRelationRecords")); }
public ActionResult DeleteConfirm(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChemAnalystContext _context = new ChemAnalystContext(); var companyProfileRecord = _context.CompanyProfRecordNew.SingleOrDefault(c => c.Id == id); if (companyProfileRecord == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } _context.CompanyProfRecordNew.Remove(companyProfileRecord); _context.SaveChanges(); return(RedirectToAction("AllCompanyProfileRecords")); }
public ActionResult SaveHeaderContent(SA_HomeHeader UserNews) { if (UserNews.Id == 0) { UserNews.CreatedTime = DateTime.Now; _context.SA_HomeHeader.Add(UserNews); _context.SaveChangesAsync(); } else { SA_HomeHeader EditNews = _context.SA_HomeHeader.Where(Cat => Cat.Id == UserNews.Id).FirstOrDefault(); EditNews.EmailAddress = UserNews.EmailAddress; EditNews.OfficeAddress = UserNews.OfficeAddress; EditNews.PhoneNumber = UserNews.PhoneNumber; EditNews.CreatedTime = UserNews.CreatedTime; _context.Entry(EditNews).State = EntityState.Modified; int x = _context.SaveChanges(); } return(RedirectToAction("HeaderContent")); }
public ActionResult SaveCompanyProfile(CompanyProfRecordViewModel viewModel) { if (!ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChemAnalystContext _context = new ChemAnalystContext(); var companyProfileInDb = _context.CompanyProfRecords.SingleOrDefault(c => c.Id == viewModel.Id); if (companyProfileInDb == null) { return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } companyProfileInDb.FinancialYearId = viewModel.FinancialYearId; companyProfileInDb.SA_CompanyId = viewModel.SA_CompanyId; companyProfileInDb.Revenues = viewModel.Revenues; companyProfileInDb.Growth = viewModel.Growth; _context.SaveChanges(); return(RedirectToAction("AllCompanyProfileRecords")); }
public ActionResult Import(CompanyProductFormViewModel viewModel) { if (viewModel.excelFile == null || viewModel.excelFile.ContentLength == 0) { //handel error ViewBag.ErrorMessage = "This field is required"; return(View("Index")); } else { ChemAnalystContext _context = new ChemAnalystContext(); string FileExtension = Path.GetExtension(viewModel.excelFile.FileName); string FileName = Path.GetFileName(viewModel.excelFile.FileName); if (FileExtension.ToLower() == ".xls") { viewModel.excelFile.SaveAs(Server.MapPath("~/ExcelFiles/") + FileName); string FilePath = Server.MapPath("~/ExcelFiles/" + FileName); OleDbConnection OleConn = null; OleConn = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0;"); OleConn.Open(); DataTable DT = OleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string GetExcelSheetName = DT.Rows[0]["Table_Name"].ToString(); OleDbDataAdapter DA = new OleDbDataAdapter("SELECT * FROM [" + GetExcelSheetName + "]", OleConn); DataSet DS = new DataSet(); DA.Fill(DS); //foreach (DataRow DR in DS.Tables[0].Rows) //{ // CompanyProduct companyProduct = new CompanyProduct(); // companyProduct.ProductName = DR[0].ToString(); // companyProduct.Segment = DR[1].ToString(); // companyProduct.IsSelected = false; // _context.CompanyProducts.Add(companyProduct); //} //_context.SaveChanges(); foreach (DataRow DR in DS.Tables[0].Rows) { SA_Product companyProduct = new SA_Product(); companyProduct.ProductName = DR[0].ToString(); companyProduct.ProductDiscription = DR[1].ToString(); companyProduct.Meta = DR[2].ToString(); companyProduct.MetaDiscription = DR[3].ToString(); companyProduct.status = Convert.ToInt32(DR[4].ToString()); companyProduct.CreatedTime = Convert.ToDateTime(DR[5]); companyProduct.ProductImg = DR[6].ToString(); companyProduct.Category = Convert.ToInt32(DR[7].ToString()); companyProduct.IsSelected = false; _context.SA_Product.Add(companyProduct); } _context.SaveChanges(); } else { ViewBag.ErrorMessage = "Only .xls file allowed"; return(View("Index")); } } return(RedirectToAction("AllCompanyProducts")); }
public bool EditRole(SA_RoleViewModel RoleViewModel) { // Role.CreatedDate = DateTime.Now; SA_Role Role = _context.SA_Role.Where(role => role.id == RoleViewModel.id).FirstOrDefault(); Role.RoleDiscription = RoleViewModel.RoleDiscription; Role.Role = RoleViewModel.Role; _context.Entry(Role).State = EntityState.Modified; int x = _context.SaveChanges(); List <SA_RoleWiseAccess> Editrole = _context.SA_RoleWiseAccess.Where(role => role.RoleId == RoleViewModel.id).ToList(); foreach (var item in Editrole) { _context.Entry(item).State = EntityState.Deleted; _context.SaveChanges(); } if (RoleViewModel.ChemicalPricing == true) { SA_RoleWiseAccess access = new Models.SA_RoleWiseAccess(); access.RoleId = Role.id; access.Pageid = 1; access.access = true; access.PageDiscription = "Chemical Pricing"; access.CreatedTime = DateTime.Now; _context.SA_RoleWiseAccess.Add(access); _context.SaveChanges(); } if (RoleViewModel.MarketAnalysis == true) { SA_RoleWiseAccess access = new Models.SA_RoleWiseAccess(); access.RoleId = Role.id; access.Pageid = 2; access.access = true; access.PageDiscription = "Market Analysis"; access.CreatedTime = DateTime.Now; _context.SA_RoleWiseAccess.Add(access); _context.SaveChanges(); } if (RoleViewModel.CompanyProfile == true) { SA_RoleWiseAccess access = new Models.SA_RoleWiseAccess(); access.RoleId = Role.id; access.Pageid = 3; access.access = true; access.PageDiscription = "Company Profile"; access.CreatedTime = DateTime.Now; _context.SA_RoleWiseAccess.Add(access); _context.SaveChanges(); } if (RoleViewModel.IndustryReports == true) { SA_RoleWiseAccess access = new Models.SA_RoleWiseAccess(); access.RoleId = Role.id; access.Pageid = 4; access.access = true; access.PageDiscription = "Industry Reports"; access.CreatedTime = DateTime.Now; _context.SA_RoleWiseAccess.Add(access); _context.SaveChanges(); } if (RoleViewModel.News == true) { SA_RoleWiseAccess access = new Models.SA_RoleWiseAccess(); access.RoleId = Role.id; access.Pageid = 5; access.access = true; access.PageDiscription = "News"; access.CreatedTime = DateTime.Now; _context.SA_RoleWiseAccess.Add(access); _context.SaveChanges(); } if (RoleViewModel.Deals == true) { SA_RoleWiseAccess access = new Models.SA_RoleWiseAccess(); access.RoleId = Role.id; access.Pageid = 6; access.access = true; access.PageDiscription = "Deals"; access.CreatedTime = DateTime.Now; _context.SA_RoleWiseAccess.Add(access); _context.SaveChanges(); } if (RoleViewModel.SubscriptionManagement == true) { SA_RoleWiseAccess access = new Models.SA_RoleWiseAccess(); access.RoleId = Role.id; access.Pageid = 7; access.access = true; access.PageDiscription = "Subscription Management"; access.CreatedTime = DateTime.Now; _context.SA_RoleWiseAccess.Add(access); _context.SaveChanges(); } return(x == 0 ? false : true); }
public async Task <bool> AddCustWiseAccess(string id, int Custid) { try { int x = 0; string[] items = id.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (var i in items) { if (Convert.ToInt32(i) == 1) { CustWiseAccess access = new Models.CustWiseAccess(); access.CustId = Custid; access.Pageid = 1; access.access = true; access.PageDiscription = "Chemical Pricing"; access.CreatedTime = DateTime.Now; _context.CustWiseAccess.Add(access); x = _context.SaveChanges(); } if (Convert.ToInt32(i) == 2) { CustWiseAccess access = new Models.CustWiseAccess(); access.CustId = Custid; access.Pageid = 2; access.access = true; access.PageDiscription = "Market Analysis"; access.CreatedTime = DateTime.Now; _context.CustWiseAccess.Add(access); x = _context.SaveChanges(); } if (Convert.ToInt32(i) == 3) { CustWiseAccess access = new Models.CustWiseAccess(); access.CustId = Custid; access.Pageid = 3; access.access = true; access.PageDiscription = "Company Profile"; access.CreatedTime = DateTime.Now; _context.CustWiseAccess.Add(access); x = _context.SaveChanges(); } if (Convert.ToInt32(i) == 4) { CustWiseAccess access = new Models.CustWiseAccess(); access.CustId = Custid; access.Pageid = 4; access.access = true; access.PageDiscription = "Industry Reports"; access.CreatedTime = DateTime.Now; _context.CustWiseAccess.Add(access); x = _context.SaveChanges(); } if (Convert.ToInt32(i) == 5) { CustWiseAccess access = new Models.CustWiseAccess(); access.CustId = Custid; access.Pageid = 5; access.access = true; access.PageDiscription = "News"; access.CreatedTime = DateTime.Now; _context.CustWiseAccess.Add(access); x = _context.SaveChanges(); } if (Convert.ToInt32(i) == 6) { CustWiseAccess access = new Models.CustWiseAccess(); access.CustId = Custid; access.Pageid = 6; access.access = true; access.PageDiscription = "Deals"; access.CreatedTime = DateTime.Now; _context.CustWiseAccess.Add(access); x = _context.SaveChanges(); } if (Convert.ToInt32(i) == 7) { CustWiseAccess access = new Models.CustWiseAccess(); access.CustId = Custid; access.Pageid = 7; access.access = true; access.PageDiscription = "Subscription Management"; access.CreatedTime = DateTime.Now; _context.CustWiseAccess.Add(access); x = await _context.SaveChangesAsync(); } } return(x == 0 ? false : true); } catch (Exception ex) { return(false); } }
public ActionResult Import(CompanyProfRecordViewModel viewModel) { if (!ModelState.IsValid) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (viewModel.excelFile == null || viewModel.excelFile.ContentLength == 0) { //handel error ViewBag.ErrorMessage = "This field is required"; ChemAnalystContext _context = new ChemAnalystContext(); var viewModelIndex = new CompanyProfRecordViewModel() { FinancialYear = _context.FinancialYears.ToList(), SA_Company = _context.SA_Company.ToList() }; return(View("Index", viewModelIndex)); } else { ChemAnalystContext _context = new ChemAnalystContext(); string FileExtension = Path.GetExtension(viewModel.excelFile.FileName); string FileName = Path.GetFileName(viewModel.excelFile.FileName); FileName = FileName + "_" + Guid.NewGuid().ToString(); if (FileExtension.ToLower() == ".xls") { viewModel.excelFile.SaveAs(Server.MapPath("~/ExcelFiles/") + FileName); string FilePath = Server.MapPath("~/ExcelFiles/" + FileName); OleDbConnection OleConn = null; OleConn = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0;"); OleConn.Open(); DataTable DT = OleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string GetExcelSheetName = DT.Rows[0]["Table_Name"].ToString(); OleDbDataAdapter DA = new OleDbDataAdapter("SELECT * FROM [" + GetExcelSheetName + "]", OleConn); DataSet DS = new DataSet(); DA.Fill(DS); OleConn.Close(); foreach (DataRow DR in DS.Tables[0].Rows) { var yr = DR[0].ToString(); //if (_context.CompanyProfRecordNew.FirstOrDefault(x => x.SA_CompanyId == viewModel.SA_CompanyId && x.FinancialYearId == viewModel.FinancialYearId) == null) if (_context.CompanyProfRecordNew.FirstOrDefault(x => x.SA_CompanyId == viewModel.SA_CompanyId && x.year == yr) == null) { try { CompanyProfRecordNew cpr = new CompanyProfRecordNew(); cpr.year = DR[0].ToString(); cpr.Revenue = Convert.ToDecimal(DR[1]); cpr.Growth = Convert.ToInt16(DR[2]); cpr.PBT = Convert.ToInt16(DR[3]); cpr.Margin = Convert.ToDecimal(DR[4]); cpr.Pat = Convert.ToDecimal(DR[5]); cpr.Margin1 = Convert.ToDecimal(DR[6]); cpr.Liablities = Convert.ToDecimal(DR[7]); cpr.SA_CompanyId = viewModel.SA_CompanyId; cpr.FinancialYearId = 0; cpr.CreateDate = DateTime.Now; _context.CompanyProfRecordNew.Add(cpr); _context.SaveChanges(); } catch (Exception ex) { ViewBag.ErrorMessage = "Import operation failed. Please upload a valid formate for import."; var viewModelIndex = new CompanyProfRecordViewModel() { FinancialYear = _context.FinancialYears.ToList(), SA_Company = _context.SA_Company.ToList() }; return(View("Index", viewModelIndex)); } } else { ViewBag.ErrorMessage = "Financial data already exists with same company for same financial year"; var viewModelIndex = new CompanyProfRecordViewModel() { FinancialYear = _context.FinancialYears.ToList(), SA_Company = _context.SA_Company.ToList() }; return(View("Index", viewModelIndex)); } } } else { ViewBag.ErrorMessage = "Only .xls file allowed"; var viewModelIndex = new CompanyProfRecordViewModel() { FinancialYear = _context.FinancialYears.ToList(), SA_Company = _context.SA_Company.ToList() }; return(View("Index", viewModelIndex)); } return(RedirectToAction("AllCompanyProfileRecords")); } }
public ActionResult Import(CompanyProfFormViewModel viewModel) { if (viewModel.excelFile == null || viewModel.excelFile.ContentLength == 0) { //handel error ViewBag.ErrorMessage = "This field is required"; return(View("Index")); } else { ChemAnalystContext _context = new ChemAnalystContext(); string FileExtension = Path.GetExtension(viewModel.excelFile.FileName); string FileName = Path.GetFileName(viewModel.excelFile.FileName); if (FileExtension.ToLower() == ".xls") { viewModel.excelFile.SaveAs(Server.MapPath("~/ExcelFiles/") + FileName); string FilePath = Server.MapPath("~/ExcelFiles/" + FileName); OleDbConnection OleConn = null; OleConn = new OleDbConnection(@"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0;"); OleConn.Open(); DataTable DT = OleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string GetExcelSheetName = DT.Rows[0]["Table_Name"].ToString(); OleDbDataAdapter DA = new OleDbDataAdapter("SELECT * FROM [" + GetExcelSheetName + "]", OleConn); DataSet DS = new DataSet(); DA.Fill(DS); //foreach (DataRow DR in DS.Tables[0].Rows) //{ // CompanyProf companyProf = new CompanyProf(); // companyProf.CompanyName = DR[0].ToString(); // companyProf.RegistrationDate = Convert.ToDateTime(DR[1]); // companyProf.Cin = DR[2].ToString(); // companyProf.Category = DR[3].ToString(); // companyProf.Address = DR[4].ToString(); // companyProf.Contact = DR[5].ToString(); // companyProf.NumberOfEmployee = Convert.ToInt32(DR[6]); // companyProf.ManagingDirector = DR[7].ToString(); // companyProf.Strength = DR[8].ToString(); // companyProf.Weakness = DR[9].ToString(); // companyProf.Oppertunity = DR[10].ToString(); // companyProf.Threat = DR[11].ToString(); // companyProf.ExpansionPlans = DR[12].ToString(); // _context.CompanyProfs.Add(companyProf); //} //_context.SaveChanges(); foreach (DataRow DR in DS.Tables[0].Rows) { SA_Company company = new SA_Company(); company.Name = DR[0].ToString(); company.Description = DR[1].ToString(); company.Logo = DR[2].ToString(); company.RegDate = Convert.ToDateTime(DR[3]); company.CIN = DR[4].ToString(); company.Category = DR[5].ToString(); company.Address = DR[6].ToString(); company.NOE = DR[7].ToString(); company.CEO = DR[8].ToString(); company.Meta = DR[9].ToString(); company.MetaDescription = DR[10].ToString(); company.website = DR[11].ToString(); company.phoneNo = DR[12].ToString(); company.fax = DR[13].ToString(); company.EmailId = DR[14].ToString(); company.CreatedTime = DateTime.Now; _context.SA_Company.Add(company); } _context.SaveChanges(); } else { ViewBag.ErrorMessage = "Only .xls file allowed"; return(View("Index")); } } return(RedirectToAction("AllCompanyProf")); }
internal int CheckExistingdata(string Filename, string ImportType) { int x = 0; if (ImportType == "Yearly") { List <SA_ChemPriceYearly> obj = _context.SA_ChemPriceYearly.Where(Year => Year.FileName == Filename).ToList(); foreach (SA_ChemPriceYearly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Monthly") { List <SA_ChemPriceMonthly> obj = _context.SA_ChemPriceMonthly.Where(Year => Year.FileName == Filename).ToList(); foreach (SA_ChemPriceMonthly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Quarterly") { List <SA_ChemPriceQuarterly> obj = _context.SA_ChemPriceQuarterly.Where(Year => Year.FileName == Filename).ToList(); foreach (SA_ChemPriceQuarterly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Daily basis") { List <SA_ChemPriceDaily> obj = _context.SA_ChemPriceDaily.Where(Year => Year.FileName == Filename).ToList(); foreach (SA_ChemPriceDaily PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Daily Bulk") { List <SA_ChemPriceDailyAverage> obj = _context.SA_ChemPriceDailyAverage.Where(Year => Year.FileName == Filename).ToList(); foreach (SA_ChemPriceDailyAverage PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Chemical 1") { List <SA_Chem1PriceWeekly> obj = _context.SA_Chem1PriceWeekly.ToList(); foreach (SA_Chem1PriceWeekly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Chemical 2") { List <SA_Chem2PriceWeekly> obj = _context.SA_Chem2PriceWeekly.ToList(); foreach (SA_Chem2PriceWeekly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Chemical 3") { List <SA_Chem3PriceWeekly> obj = _context.SA_Chem3PriceWeekly.ToList(); foreach (SA_Chem3PriceWeekly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Chemical 4") { List <SA_Chem4PriceWeekly> obj = _context.SA_Chem4PriceWeekly.ToList(); foreach (SA_Chem4PriceWeekly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Chemical 5") { List <SA_Chem5PriceWeekly> obj = _context.SA_Chem5PriceWeekly.ToList(); foreach (SA_Chem5PriceWeekly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } else if (ImportType == "Chemical 6") { List <SA_Chem6PriceWeekly> obj = _context.SA_Chem6PriceWeekly.ToList(); foreach (SA_Chem6PriceWeekly PriceYearly in obj) { _context.Entry(PriceYearly).State = EntityState.Deleted; x = _context.SaveChanges(); } } return(x); }