private void deleteMarkKafedra(int idCurrentKafedra, MarkObjectKafedra m) { Mark_Kafedra delMarkK = db.Mark_Kafedra.Single( mt => mt.Id_Kafedra == idCurrentKafedra && mt.Id_Criteria == m.CriteriaId); if (m.IsRemoved != null) { List <Status_Doc_Kafedra> delDocs = db.Status_Doc_Kafedra.Where(d => d.Id_Mark_Kafedra == delMarkK.Id).ToList(); foreach (var d in delDocs) { db.Status_Doc_Kafedra.Remove(d); string fullPath = Request.MapPath("~/documents/" + d.Link_Doc); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } } db.Mark_Kafedra.Remove(delMarkK); db.SaveChanges(); }
private void editMarkKafedra(int idCurrentKafedra, MarkObjectKafedra m, Criteria_Kafedra selectedCriteria) { Mark_Kafedra editMarkK = db.Mark_Kafedra.Single( mt => mt.Id_Kafedra == idCurrentKafedra && mt.Id_Criteria == m.CriteriaId); List <Status_Doc_Kafedra> oldFiles = db.Status_Doc_Kafedra.Where(d => d.Id_Mark_Kafedra == editMarkK.Id).ToList(); if (m.Count != editMarkK.Kolvo_ed) { editMarkK.Kolvo_ed = m.Count; editMarkK.Kolvo_Mark = (int)selectedCriteria.Mark * m.Count; editMarkK.Date = DateTime.Now; db.SaveChanges(); } refreshDocs(oldFiles, m, editMarkK); }
private void createMarkKafedra(int idCurrentKafedra, MarkObjectKafedra m, Criteria_Kafedra selectedCriteria) { Mark_Kafedra newMarkKafedra = new Mark_Kafedra(); newMarkKafedra.Id_Kafedra = idCurrentKafedra; newMarkKafedra.Id_Criteria = m.CriteriaId; newMarkKafedra.Kolvo_ed = m.Count; if (m.NewFiles == null || m.NewFiles[0] == null) { newMarkKafedra.Status = -2; } else { newMarkKafedra.Status = 0; } newMarkKafedra.Kolvo_Mark = (int)selectedCriteria.Mark * m.Count; newMarkKafedra.Date = DateTime.Now; if (m.NewFiles != null) { newMarkKafedra.Status_Doc_Kafedra = new List <Status_Doc_Kafedra>(); foreach (var item in m.NewFiles) { if (item != null) { var document = new Status_Doc_Kafedra() { Link_Doc = Guid.NewGuid() + Path.GetFileName(item.FileName), Name = item.FileName, FileType = item.ContentType, FileContent = item.ContentLength }; newMarkKafedra.Status_Doc_Kafedra.Add(document); item.SaveAs(Path.Combine(Server.MapPath("~/documents"), document.Link_Doc)); } } } db.Mark_Kafedra.Add(newMarkKafedra); db.SaveChanges(); }
private void refreshDocs(List <Status_Doc_Kafedra> oldFiles, MarkObjectKafedra m, Mark_Kafedra editMarkK) { bool isChanged = false; if (oldFiles.Count != 0) { for (int i = 0; i < m.IsRemoved.Count; i++) { if (m.IsRemoved[i]) { db.Status_Doc_Kafedra.Remove(oldFiles[i]); string fullPath = Request.MapPath("~/documents/" + oldFiles[i].Link_Doc); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } isChanged = true; } } } if (m.NewFiles != null) { if (oldFiles.Count == 0) { editMarkK.Status_Doc_Kafedra = new List <Status_Doc_Kafedra>(); } foreach (var nf in m.NewFiles) { if (nf != null) { var document = new Status_Doc_Kafedra() { Link_Doc = Guid.NewGuid() + Path.GetFileName(nf.FileName), Name = nf.FileName, FileType = nf.ContentType, FileContent = nf.ContentLength }; editMarkK.Status_Doc_Kafedra.Add(document); nf.SaveAs(Path.Combine(Server.MapPath("~/documents"), document.Link_Doc)); isChanged = true; } } } if (isChanged) { editMarkK.Date = DateTime.Now; int cntRemoved = 0; if (m.IsRemoved != null) { foreach (var r in m.IsRemoved) { if (r) { cntRemoved++; } } } bool bc = false; if (m.ExistingFiles != null) { if (m.ExistingFiles.Count == cntRemoved && (m.NewFiles == null || m.NewFiles[0] == null)) { editMarkK.Status = -2; bc = true; } } else if (m.NewFiles == null || m.NewFiles[0] == null) { editMarkK.Status = -2; bc = true; } if (!bc) { editMarkK.Status = 0; } } db.SaveChanges(); }