public Decimal SaveProductVideo(ProductVideos productVideo) { using (var context = new UniversityEntities()) { var productVideoExising = context.ProductVideos.FirstOrDefault(y => y.Id == productVideo.Id && y.IsDeleted != true); if (productVideoExising != null) { productVideoExising.AssocitedCustID = productVideo.AssocitedCustID; productVideoExising.UpdatedDate = DateTime.UtcNow; productVideoExising.Title = productVideo.Title; productVideoExising.Decription = productVideo.Decription; if (!string.IsNullOrWhiteSpace(productVideo.VideoURL)) { productVideoExising.VideoURL = productVideo.VideoURL; } if (!string.IsNullOrWhiteSpace(productVideo.ThumbnailURL)) { productVideoExising.ThumbnailURL = productVideo.ThumbnailURL; } context.SaveChanges(); return(productVideoExising.Id); } else { productVideo.CreatedDate = DateTime.UtcNow; context.ProductVideos.Add(productVideo); context.SaveChanges(); return(productVideo.Id); } } }
public bool UpdateProductvideo(ProductVideos model) { using (var context = new UniversityEntities()) { var productvideo = context.ProductVideos.FirstOrDefault(y => y.Id == model.Id && y.IsDeleted != true); if (productvideo != null) { productvideo.Decription = model.Decription; productvideo.Title = model.Title; productvideo.ProductId = model.ProductId; productvideo.ThumbnailURL = model.ThumbnailURL; //productvideo.AssocitedID = model.AssocitedID; if (!string.IsNullOrWhiteSpace(model.VideoURL)) { productvideo.VideoURL = model.VideoURL; } productvideo.IsDeleted = false; productvideo.UpdatedDate = DateTime.UtcNow; context.SaveChanges(); } else { model.CreatedDate = DateTime.UtcNow; model.IsDeleted = false; context.ProductVideos.Add(model); context.SaveChanges(); } return(true); } }
public Decimal SaveProductDocument(ProductDocuments productDocument) { using (var context = new UniversityEntities()) { var productDocumentExising = context.ProductDocuments.FirstOrDefault(y => y.Id == productDocument.Id && y.IsDeleted != true); if (productDocumentExising != null) { productDocument.AssocitedCustID = productDocument.AssocitedCustID; productDocumentExising.UpdatedDate = DateTime.UtcNow; if (!string.IsNullOrWhiteSpace(productDocument.DocumentURL)) { productDocumentExising.DocumentURL = productDocument.DocumentURL; } productDocumentExising.Decription = productDocument.Decription; productDocumentExising.DocumentDisplayName = productDocument.DocumentDisplayName; productDocumentExising.Title = productDocument.Title; context.SaveChanges(); return(productDocumentExising.Id); } else { productDocument.CreatedDate = DateTime.UtcNow; context.ProductDocuments.Add(productDocument); context.SaveChanges(); return(productDocument.Id); } } }
public bool SaveProductUserGuide(ProductUserGuide productUserGuide) { using (var context = new UniversityEntities()) { var guide = context.ProductUserGuide.FirstOrDefault(y => y.Id == productUserGuide.Id && y.IsDeleted != true); if (guide != null) { guide.AssocitedCustID = productUserGuide.AssocitedCustID; guide.Description = productUserGuide.Description; guide.Title = productUserGuide.Title; guide.DocumentURL = productUserGuide.DocumentURL; if (productUserGuide.ImageURL != null) { guide.ImageURL = productUserGuide.ImageURL; } guide.UpdatedDate = DateTime.UtcNow; guide.ImageALT = productUserGuide.ImageALT; context.SaveChanges(); } else { productUserGuide.CreatedDate = DateTime.UtcNow; context.ProductUserGuide.Add(productUserGuide); context.SaveChanges(); } return(true); } }
private void btnCreateSubject_Click(object sender, EventArgs e) { string subjectName = txtSubjectname.Text.Trim(); Subject subject = db.Subjects.FirstOrDefault(s => s.Name.ToLower() == subjectName.ToLower()); if (subject != null) { MessageBox.Show("Subject with this name is already exists", "Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(subjectName)) { MessageBox.Show("Please enter subjectname correctly", "Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Subject newSubject = new Subject { Name = subjectName, Status = true }; db.Subjects.Add(newSubject); db.SaveChanges(); txtSubjectname.Clear(); MessageBox.Show($"Subject {subjectName} created successfully!", "Creation Success", MessageBoxButtons.OK, MessageBoxIcon.Information); updateSubjectsDataGrid(); txtSubjectname.Clear(); }
private void acceptButton_Click(object sender, RoutedEventArgs e) { if (!CheckFields()) { return; } _teacher.Name = nameBlock.Text; _teacher.Surname = surnameBlock.Text; _teacher.StartYear = startYearPicker.SelectedDate.Value.Year; _teacher.Photo = image.Source.ToString(); if (teacherWasNull) { _context.Teachers.Add(_teacher); } else { _context.Entry(_teacher).State = EntityState.Modified; } _context.SaveChanges(); DialogResult = true; }
public IHttpActionResult PutStudent(int id, Student student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != student.StudentID) { return(BadRequest()); } db.Entry(student).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public bool AddOrUpdateHomeSlider(HomeSlider model) { using (var context = new UniversityEntities()) { int AdminID = Convert.ToInt32(HttpContext.Current.Session["AdminLoginID"]); var slider = context.HomeSlider.FirstOrDefault(y => y.Id == model.Id && y.IsDeleted != true); if (slider != null) { slider.ProductId = model.ProductId; slider.AssocitedCustID = AdminID; slider.TextDescription = model.TextDescription; slider.Link = model.Link; slider.ImageALT = model.ImageALT; slider.IsDeleted = false; if (!string.IsNullOrWhiteSpace(model.ImageURL)) { slider.ImageURL = model.ImageURL; } slider.UpdatedDate = DateTime.UtcNow; context.SaveChanges(); } else { model.AssocitedCustID = AdminID; model.IsDeleted = false; model.CreatedDate = DateTime.UtcNow; context.HomeSlider.Add(model); context.SaveChanges(); } return(true); } }
public Decimal SaveProductFAQVideo(ProductFAQVideos productFAQVideo) { using (var context = new UniversityEntities()) { var productFaqVideo = context.ProductFAQVideos.FirstOrDefault(y => y.Id == productFAQVideo.Id && y.IsDeleted != true); if (productFaqVideo != null) { productFaqVideo.UpdatedDate = DateTime.UtcNow; if (!string.IsNullOrWhiteSpace(productFAQVideo.VideoURL)) { productFaqVideo.VideoURL = productFAQVideo.VideoURL; } if (!string.IsNullOrWhiteSpace(productFAQVideo.ImageURL)) { productFaqVideo.ImageURL = productFAQVideo.ImageURL; } context.SaveChanges(); return(productFaqVideo.Id); } else { //productFAQ.Id = Guid.NewGuid(); productFAQVideo.CreatedDate = DateTime.UtcNow; context.ProductFAQVideos.Add(productFAQVideo); context.SaveChanges(); return(productFAQVideo.Id); } } }
public bool AddOrUpdateSubCategory(SubCategoryMaster model) { using (var context = new UniversityEntities()) { var subcategory = context.SubCategoryMaster.FirstOrDefault(y => y.Id == model.Id && y.IsDeleted != true); var categoryId = context.CategoryMaster.FirstOrDefault().Id; if (subcategory != null) { if (!string.IsNullOrWhiteSpace(model.ImageURL)) { subcategory.ImageURL = model.ImageURL; } subcategory.AssocitedCustID = Convert.ToInt32(HttpContext.Current.Session["AdminLoginID"]); subcategory.Name = model.Name; subcategory.CategoryId = categoryId; subcategory.UpdatedDate = DateTime.UtcNow; subcategory.ImageALT = model.ImageALT; context.SaveChanges(); } else { model.AssocitedCustID = Convert.ToInt32(HttpContext.Current.Session["AdminLoginID"]); model.CategoryId = categoryId; model.CreatedDate = DateTime.UtcNow; model.IsDeleted = false; context.SubCategoryMaster.Add(model); context.SaveChanges(); } return(true); } }
private void acceptButton_Click(object sender, RoutedEventArgs e) { if (!CheckFields()) { return; } _student.Name = nameBlock.Text; _student.Surname = surnameBlock.Text; _student.Gender = listGenders.Text; _student.Birthday = birthdayPicker.SelectedDate.Value; var group = listGroups.SelectedItem as Group; _student.GroupId = group.Id; _student.Photo = image.Source.ToString(); if (studentWasNull) { _context.Students.Add(_student); } else { _context.Entry(_student).State = EntityState.Modified; } _context.SaveChanges(); DialogResult = true; }
private void btnCreateGroup_Click(object sender, EventArgs e) { string groupName = txtGroupname.Text; Subject subject = db.Subjects.FirstOrDefault(s => s.Name == groupName); if (subject != null) { MessageBox.Show("Group with this name is already exists", "Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(groupName)) { MessageBox.Show("Please enter groupname correctly", "Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Group newGroup = new Group { Name = groupName, Status = true }; db.Groups.Add(newGroup); db.SaveChanges(); txtGroupname.Clear(); MessageBox.Show($"Group {groupName} created successfully!", "Creation Success", MessageBoxButtons.OK, MessageBoxIcon.Information); updateGroupsDataGrid(); }
private void acceptButton_Click(object sender, RoutedEventArgs e) { if (!CheckFields()) { return; } _group.Name = nameBox.Text; _group.YearFormation = yearFormationPicker.SelectedDate.Value.Year; var specialties = listSpecialties.SelectedItem as Specialty; _group.SpecialtyId = specialties.Id; if (groupWasNull) { _context.Groups.Add(_group); } else { _context.Entry(_group).State = EntityState.Modified; } _context.SaveChanges(); DialogResult = true; }
public bool AddCategoryUserMapping(CategoryUserMapping model) { using (var context = new UniversityEntities()) { var categoryMapping = context.CategoryUserMapping.FirstOrDefault(y => y.ID == model.ID && y.IsDeleted != true); // var categoryId = context.CategoryMaster.FirstOrDefault().Id; if (categoryMapping != null) { categoryMapping.AdminID = Convert.ToInt32(HttpContext.Current.Session["AdminLoginID"]); categoryMapping.UserID = model.UserID; categoryMapping.CategoryID = model.CategoryID; categoryMapping.UpdatedDate = DateTime.UtcNow; context.SaveChanges(); } else { model.AdminID = Convert.ToInt32(HttpContext.Current.Session["AdminLoginID"]); //model.CategoryID = categoryId; model.CreatedDate = DateTime.UtcNow; model.IsDeleted = false; context.CategoryUserMapping.Add(model); context.SaveChanges(); } return(true); } }
public ActionResult Create([Bind(Include = "Id,Title")] Models.University university) { if (ModelState.IsValid) { db.Universities.Add(university); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(university)); }
public ActionResult Create([Bind(Include = "CourseID,Title,Credits")] Course course) { if (ModelState.IsValid) { db.Course.Add(course); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(course)); }
public ActionResult Create([Bind(Include = "maBaiViet,tieuDe,noiDung,ngayDang")] BaiViet baiViet) { if (ModelState.IsValid) { db.BaiViets.Add(baiViet); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(baiViet)); }
public ActionResult Create([Bind(Include = "Id,Title")] Role role) { if (ModelState.IsValid) { db.Roles.Add(role); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(role)); }
public ActionResult Create([Bind(Include = "StudentId,FirstName,LastName,EnrollmentDate")] Student student) { if (ModelState.IsValid) { db.Students.Add(student); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Create([Bind(Include = "Id,Group,Evalution,FirstName,LastName,MiddleName")] EpmDepView epmDepView) { if (ModelState.IsValid) { db.EpmDepViews.Add(epmDepView); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(epmDepView)); }
/// <summary> /// 发送给特定组 /// </summary> /// <param name="groupName">组名</param> /// <param name="name">发送者</param> /// <param name="message">消息内容</param> public void sendToGroup(string groupName, string name, string message, string userimg, string lastChatId) { //接受方没有在线,把信息保存到数据库,并标记为未读(a.没有最近聊天记录,则添加新的最近聊天记录和聊天信息;b.有最近聊天记录, //则添加新的聊天信息,并更新最近聊天记录) if (lastChatId != "") //有最近聊天记录 { //添加新的聊天记录 int lastChatint = Convert.ToInt32(lastChatId); Message newMesssge = new Message(); newMesssge.lastChatId = lastChatint; newMesssge.messageContent = message; newMesssge.messageReceiveUserId = Convert.ToInt32(groupName); newMesssge.messageSendUserId = Convert.ToInt32(name); newMesssge.messageTime = DateTime.Now; db.Message.Add(newMesssge); //更新最近聊天信息 LastChat uplastChat = db.LastChat.Where(o => o.lastChatId == lastChatint).FirstOrDefault(); uplastChat.lastChatContent = message; db.SaveChanges(); Clients.Group(groupName).recieveMessage(new MessageModel() { MsgType = "1", UserName = name, Message = message, UserImg = userimg, lastChatId = lastChatId }); } else { //添加新的最近联系人 LastChat newLastChat = new LastChat(); newLastChat.lastChatContent = message; newLastChat.lastChatfriendId = Convert.ToInt32(groupName); newLastChat.lastChatTime = DateTime.Now; newLastChat.lastChatUserId = Convert.ToInt32(name); db.LastChat.Add(newLastChat); db.SaveChanges(); //添加新的聊天记录 Message newMesssge = new Message(); newMesssge.messageContent = message; newMesssge.messageReceiveUserId = Convert.ToInt32(groupName); newMesssge.messageSendUserId = Convert.ToInt32(name); newMesssge.messageTime = DateTime.Now; int id = db.LastChat.Where(o => o.lastChatfriendId == newLastChat.lastChatfriendId && o.lastChatUserId == newLastChat.lastChatUserId).FirstOrDefault().lastChatId; newMesssge.lastChatId = id; db.Message.Add(newMesssge); db.SaveChanges(); string stringId = Convert.ToString(id); Clients.Group(groupName).recieveMessage(new MessageModel() { MsgType = "1", UserName = name, Message = message, UserImg = userimg, lastChatId = stringId }); } }
public ActionResult Create([Bind(Include = "Id,Title,IdUniversity")] Faculty faculty) { if (ModelState.IsValid) { db.Faculties.Add(faculty); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdUniversity = new SelectList(db.Universities, "Id", "Title", faculty.IdUniversity); return(View(faculty)); }
public ActionResult Create([Bind(Include = "Id,Login,Password,IdRole")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdRole = new SelectList(db.Roles, "Id", "Title", user.IdRole); return(View(user)); }
public ActionResult Create([Bind(Include = "Id,IdStudent,IdOldUniversity,IdNewUniversity,IdOldFaculty,IdOldGroup,IdNewGroup,DateTransfer")] Transfer transfer) { if (ModelState.IsValid) { db.Transfers.Add(transfer); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdStudent = new SelectList(db.Students, "Id", "FirstName", transfer.IdStudent); return(View(transfer)); }
public ActionResult Create([Bind(Include = "Id,IdStudent,DateDeducted")] Deducted deducted) { if (ModelState.IsValid) { db.Deducteds.Add(deducted); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.IdStudent = new SelectList(db.Students, "Id", "FirstName", deducted.IdStudent); return View(deducted); }
public ActionResult Create([Bind(Include = "Id,Title,IdDepartament,OpeningDate")] Specialty specialty) { if (ModelState.IsValid) { db.Specialties.Add(specialty); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdDepartament = new SelectList(db.Departaments, "Id", "Title", specialty.IdDepartament); return(View(specialty)); }
public ActionResult Create([Bind(Include = "Id,Number,NumberOfstudent,Course,IdSpecialty")] Group group) { if (ModelState.IsValid) { db.Groups.Add(group); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdSpecialty = new SelectList(db.Specialties, "Id", "Title", group.IdSpecialty); return(View(group)); }
public ActionResult Create([Bind(Include = "Id,IdStudent,DateGraduates")] Graduate graduate) { if (ModelState.IsValid) { db.Graduates.Add(graduate); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdStudent = new SelectList(db.Students, "Id", "FirstName", graduate.IdStudent); return(View(graduate)); }
public ActionResult Create([Bind(Include = "Id,Title,IdFaculty")] Departament departament) { if (ModelState.IsValid) { db.Departaments.Add(departament); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdFaculty = new SelectList(db.Faculties, "Id", "Title", departament.IdFaculty); return(View(departament)); }
private void acceptButton_Click(object sender, RoutedEventArgs e) { if (!CheckFields()) { return; } _currentDiscipline.Name = nameBox.Text; _currentDiscipline.Code = codeBox.Text; if (currentDisciplineWasNull) { _context.Disciplines.Add(_currentDiscipline); } else { _context.Entry(_currentDiscipline).State = EntityState.Modified; } var disciplineId = _context.SaveChanges(); _discipline.DisciplineId = disciplineId; if (int.TryParse(totalHoursBox.Text, out int totalHours)) { _discipline.TotalHours = totalHours; } else { MessageBox.Show("Некорректное значение! \n" + "Введите количество часов в целочисленном формате."); return; } _discipline.AcademicYearStart = startAcademicYearPicker.SelectedDate.Value.Year; _discipline.AcademicYearEnd = endAcademicYearPicker.SelectedDate.Value.Year; _discipline.GroupId = (listGroups.SelectedItem as Group).Id; _discipline.TeacherId = (listTeachers.SelectedItem as Teacher).Id; if (disciplineWasNull) { _context.TeacherDisciplines.Add(_discipline); } else { _context.Entry(_discipline).State = EntityState.Modified; } _context.SaveChanges(); DialogResult = true; }