public ActionResult SaveCompany(SA_Company UserNews) { 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("~/ProductImages"), fileName); file.SaveAs(path); UserNews.Logo = fileName; } } UserNews.CreatedTime = DateTime.Now; if (UserNews.id == 0) { Obj.AddCompany(UserNews); } else { Obj.EditCompany(UserNews); } return(RedirectToAction("Company")); }
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> UpdateCompany(SA_Company News) { _context.Entry(News).State = EntityState.Modified; // News.ModeifiedDate = DateTime.Now; int x = await _context.SaveChangesAsync(); return(x == 0 ? false : true); }
public async Task <bool> AddCompany(SA_Company News) { // News.CreatedDate = DateTime.Now; _context.SA_Company.Add(News); int x = await _context.SaveChangesAsync(); return(x == 0 ? false : true); }
public bool DeleteCompany(int NewsId) { // News.CreatedDate = DateTime.Now; SA_Company EditNews = _context.SA_Company.Where(News => News.id == NewsId).FirstOrDefault(); _context.Entry(EditNews).State = EntityState.Deleted; 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 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")); }
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")); }
public ActionResult AddCompany() { var Model = new SA_Company(); return(View(Model)); }
public ActionResult EditCompany(int id) { SA_Company obj = Obj.GetCompanyByid(id); return(View("AddCompany", obj)); }