public ActionResult Edit([Bind(Include = "Id,FileNumber,FilePath,Comment,CreatedDate,IsActive")] FileRefrence fileRefrence) { if (ModelState.IsValid) { db.Entry(fileRefrence).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(fileRefrence)); }
public ActionResult Create([Bind(Include = "Id,FileNumber,FilePath,Comment,CreatedDate,IsActive")] FileRefrence fileRefrence) { if (ModelState.IsValid) { db.FileRefrences.Add(fileRefrence); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(fileRefrence)); }
public void Removefile(int fileid) { FileRefrence fileRefrence = db.FileRefrences.Find(fileid); string fullPath = Request.MapPath("~/" + fileRefrence.FilePath); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } db.FileRefrences.Remove(fileRefrence); db.SaveChanges(); }
public ActionResult DeleteConfirmed(int id) { FileRefrence fileRefrence = db.FileRefrences.Find(id); string fullPath = Request.MapPath("~/" + fileRefrence.FilePath); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } db.FileRefrences.Remove(fileRefrence); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: FileRefrences/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FileRefrence fileRefrence = db.FileRefrences.Find(id); if (fileRefrence == null) { return(HttpNotFound()); } return(View(fileRefrence)); }
public ActionResult Upload(int?TableID, HttpPostedFileBase file, string FileDescription, string FromDate, string ToDate) { if (TableID == null) { TempData["failed"] = "Please Select a table first"; return(RedirectToAction("Index")); } if (file != null) { try { string path1 = ""; string filetype = Path.GetExtension(file.FileName).ToLower(); if (filetype == ".xlsx" || filetype == ".xls") { if (file.ContentLength < 102400) { String unique = DateTime.Now.ToString("yyyyMMddHHmmssfff"); string filename = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath("~/Content/AttendanceFiles/") + unique + filename); var path = "Content/AttendanceFiles/" + unique + filename; path1 = Server.MapPath("~/Content/AttendanceFiles/") + unique + filename; ViewBag.FileName = filename; FileRefrence fileref = new FileRefrence(); fileref.FilePath = path; var guidid = Guid.NewGuid().ToString().Split('-')[0]; fileref.FileNumber = guidid; fileref.CreatedDate = DateTime.Now; fileref.Comment = FileDescription; db.FileRefrences.Add(fileref); db.SaveChanges(); var fileid = fileref.Id; List <AttendanceLog> myList = new List <AttendanceLog>(); var ColOrder = db.AttTableDefinations.Where(a => a.TableId == TableID).FirstOrDefault().ColumnOrder.Split(','); 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++) { AttendanceLog FileDtls = new AttendanceLog(); if (ColOrder.Length > 0) { for (var i = 1; i <= ColOrder.Length; i++) { var colelment = int.Parse(ColOrder[i - 1]); FileDtls.FileID = fileid; FileDtls.UploadedType = "File"; switch (colelment) { case 1: var olddate = workSheet.Cells[rowIterator, i].Value.ToString(); if (olddate.Contains('/')) { var oDate = olddate.Split('/'); var month = oDate[1]; var day = oDate[0]; var year = oDate[2].Split(new string[] { " " }, StringSplitOptions.None)[0]; int valmonth = int.Parse(month); if (valmonth > 12) { TempData["failed"] = "Month shouldn't be more than 12"; Removefile(fileid); return(RedirectToAction("Index")); } if (month.Length < 2) { month = "0" + month; } if (day.Length < 2) { day = "0" + day; } var newdate = day + "/" + month + "/" + year; FileDtls.Date = newdate; } else { Removefile(fileid); var oDate2 = DateTime.ParseExact(olddate, "dd/MM/yyyy", null); } //var newdate = olddate[1] + '/' + olddate[0] + '/' + olddate[2]; //var nndate = newdate.ToString("dd/mm/yyyy"); //FileDtls.Date = workSheet.Cells[rowIterator, i].Value == null ? null : Convert.ToDateTime(workSheet.Cells[rowIterator, i].Value).ToString("dd/MM/yyyy"); break; case 2: FileDtls.TimeIN = workSheet.Cells[rowIterator, i].Value == null ? null : Convert.ToDateTime(workSheet.Cells[rowIterator, i].Value).ToString("HH:mm:ss"); break; case 3: FileDtls.TimeOut = workSheet.Cells[rowIterator, i].Value == null ? null : Convert.ToDateTime(workSheet.Cells[rowIterator, i].Value).ToString("HH:mm:ss"); break; case 4: FileDtls.TimeFunction = workSheet.Cells[rowIterator, i].Value == null ? null : Convert.ToDateTime(workSheet.Cells[rowIterator, i].Value).ToString("HH:mm:ss"); break; case 5: FileDtls.FunctionID = workSheet.Cells[rowIterator, i].Value.ToString(); break; case 6: FileDtls.EmployeeID = int.Parse(workSheet.Cells[rowIterator, i].Value.ToString()); break; case 7: var checkid = int.Parse(workSheet.Cells[rowIterator, i].Value.ToString()); var machinetableid = db.AttMachineTableRefrences.Where(a => a.MachineID == checkid && a.TableID == TableID).FirstOrDefault(); if (machinetableid != null) { FileDtls.MachineTableID = machinetableid.Id; break; } else { TempData["failed"] = "MachineId " + checkid + " doesn't define to a table in the system"; Removefile(fileid); return(RedirectToAction("Index")); } break; default: TempData["failed"] = "There's an error"; Removefile(fileid); return(RedirectToAction("Index")); break; } } } myList.Add(FileDtls); } foreach (var lists in myList) { db.AttendanceLogs.Add(lists); db.SaveChanges(); } } } TempData["success"] = "Process Done Successfully"; } return(RedirectToAction("Index")); } catch (Exception e) { TempData["failed"] = e.Message; return(RedirectToAction("Index")); } } TempData["failed"] = "No file Uploaded"; return(RedirectToAction("Index")); }