public ActionResult Create(StudentModel obj) { List <object> Parameters = new List <object>(); int fid = (int)Session["FacultyID"]; obj.FacultyID = fid; //StudentTable st = new StudentTable(); Parameters.Add(obj.StudentNo); Parameters.Add(obj.StudentName); Parameters.Add(obj.StudentEmail); Parameters.Add(obj.Branch); Parameters.Add(obj.Section); Parameters.Add(obj.Year); Parameters.Add(obj.IsHosteller); Parameters.Add(obj.IsCR); Parameters.Add(obj.StudentCategory); Parameters.Add(obj.FacultyID); object[] objectarray = Parameters.ToArray(); try { int output = Db.Database.ExecuteSqlCommand("insert into StudentTable(StudentNo, StudentName, StudentEmail, Branch, Section, Year, IsHosteller, IsCR, StudentCategory, FacultyID) values(@p0,@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9)", objectarray); if (output > 0) { ViewBag.Message = "Data of Student" + obj.StudentName + "is added successfully"; } Session["StudentNo"] = obj.StudentNo; int id = (int)Session["CategoryID"]; ConnectTable CC = new ConnectTable(); CC.CategoryID = id; CC.StudentNo = obj.StudentNo; using (var context = new MailProEntities()) { // CC.PrimaryID = 1; context.ConnectTable.Add(CC); context.SaveChanges(); } } catch (SqlException ex) { if (ex.Number == 2627 || ex.Number == 2601) { Session["StudentNo"] = obj.StudentNo; int id = (int)Session["CategoryID"]; ConnectTable CC = new ConnectTable(); CC.CategoryID = id; CC.StudentNo = obj.StudentNo; using (var context = new MailProEntities()) { // CC.PrimaryID = 1; context.ConnectTable.Add(CC); context.SaveChanges(); } return(RedirectToAction("Create")); } } return(RedirectToAction("Create")); }
public void DeleteConnect(int id) { LoraPlatformEntities db = new LoraPlatformEntities(); ConnectTable data = db.ConnectTable.Find(id); db.ConnectTable.Remove(data); db.SaveChanges(); db.Dispose(); }
public void AddConnect(string deviceid, string idcard, string account) { LoraPlatformEntities db = new LoraPlatformEntities(); ConnectTable data = new ConnectTable(); data.DeviceId = deviceid; data.Elder = idcard; data.Account = account; db.ConnectTable.Add(data); db.SaveChanges(); db.Dispose(); }
public async Task <IActionResult> Create([Bind("ProductesId,SizeId,ColorId,AmountInStock")] ConnectTable connectTable) { if (ModelState.IsValid) { _context.Add(connectTable); await _context.SaveChangesAsync(); return(RedirectToAction("List")); } ViewData["ColorId"] = new SelectList(_context.Colors, "Id", "Id", connectTable.ColorId); ViewData["ProductesId"] = new SelectList(_context.Productes, "Id", "Id", connectTable.ProductesId); ViewData["SizeId"] = new SelectList(_context.Sizes, "Id", "Id", connectTable.SizeId); return(View(connectTable)); }
public async Task <IActionResult> Edit(int ProductesId, int SizeId, int ColorId, [Bind("ProductesId,SizeId,ColorId,AmountInStock")] ConnectTable connectTable) { if (ProductesId != connectTable.ProductesId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(connectTable); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConnectTableExists(connectTable.ProductesId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("List")); } ViewData["ColorId"] = new SelectList(_context.Colors, "Id", "Id", connectTable.ColorId); ViewData["ProductesId"] = new SelectList(_context.Productes, "Id", "Id", connectTable.ProductesId); ViewData["SizeId"] = new SelectList(_context.Sizes, "Id", "Id", connectTable.SizeId); return(View(connectTable)); }
/* public ActionResult StudentDetails(int StudentNo) * { * var data = Db.StudentTables.SqlQuery("Select *From StudentTable where StudentNo = " + StudentNo).SingleOrDefault(); * return View(data); * }*/ public ActionResult Upload(StudentModel obj, FormCollection formCollection) { if (Request != null) { HttpPostedFileBase file = Request.Files["UploadedFile"]; if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { string fileName = file.FileName; string fileContentType = file.ContentType; byte[] fileBytes = new byte[file.ContentLength]; var data = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength)); //var usersList = new List<StudentModel>(); using (var package = new ExcelPackage(file.InputStream)) { var currentSheet = package.Workbook.Worksheets; var workSheet = currentSheet.First(); var noOfCol = workSheet.Dimension.End.Column; var noOfRow = workSheet.Dimension.End.Row; for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++) { var user = new StudentModel(); user.StudentNo = Convert.ToInt32(workSheet.Cells[rowIterator, 1].Value.ToString()); user.StudentName = workSheet.Cells[rowIterator, 2].Value.ToString(); user.StudentEmail = workSheet.Cells[rowIterator, 3].Value.ToString(); user.Branch = workSheet.Cells[rowIterator, 4].Value.ToString(); user.Section = Convert.ToInt32(workSheet.Cells[rowIterator, 5].Value.ToString()); user.Year = Convert.ToInt32(workSheet.Cells[rowIterator, 6].Value.ToString()); user.IsHosteller = Convert.ToBoolean(Convert.ToInt32(workSheet.Cells[rowIterator, 7].Value.ToString())); user.IsCR = Convert.ToBoolean(Convert.ToInt32(workSheet.Cells[rowIterator, 8].Value.ToString())); user.StudentCategory = workSheet.Cells[rowIterator, 9].Value.ToString(); int fid = (int)Session["FacultyID"]; user.FacultyID = fid; //usersList.Add(user); List <object> Parameters = new List <object>(); obj.StudentNo = user.StudentNo; obj.StudentName = user.StudentName; obj.StudentEmail = user.StudentEmail; obj.Branch = user.Branch; obj.Section = user.Section; obj.Year = user.Year; obj.IsHosteller = user.IsHosteller; obj.IsCR = user.IsCR; obj.StudentCategory = user.StudentCategory; obj.FacultyID = user.FacultyID; Parameters.Add(obj.StudentNo); Parameters.Add(obj.StudentName); Parameters.Add(obj.StudentEmail); Parameters.Add(obj.Branch); Parameters.Add(obj.Section); Parameters.Add(obj.Year); Parameters.Add(obj.IsHosteller); Parameters.Add(obj.IsCR); Parameters.Add(obj.StudentCategory); Parameters.Add(obj.FacultyID); object[] objectarray = Parameters.ToArray(); try { int output = Db.Database.ExecuteSqlCommand("insert into StudentTable(StudentNo, StudentName, StudentEmail, Branch, Section, Year, IsHosteller, IsCR, StudentCategory, FacultyID) values(@p0,@p1,@p2,@p3,@p4,@p5,@p6,@p7,@p8,@p9)", objectarray); Session["StudentNo"] = obj.StudentNo; } catch (Exception) { ModelState.AddModelError("", "There is some error please recheck your data"); return(View()); } int id = (int)Session["CategoryID"]; ConnectTable CC = new ConnectTable(); CC.CategoryID = id; CC.StudentNo = obj.StudentNo; using (var context = new MailProEntities()) { // CC.PrimaryID = 1; context.ConnectTable.Add(CC); context.SaveChanges(); } } } } } return(View("Create")); }