/// <summary> /// Delete Book /// </summary> /// <param name="bookId"></param> /// <returns></returns> public int DeleteBook(int bookId) { using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { var result = unitOfWorks.TransactionRepository.GetDetailsbyId(bookId).ToList(); if (result != null) { result.ToList().ForEach(c => { Transaction transaction = new Transaction(); { transaction.TransactionId = c.TransactionId; unitOfWorks.TransactionRepository.Delete(transaction.TransactionId); unitOfWorks.Save(); } }); } unitOfWorks.BookRepository.Delete(bookId); unitOfWorks.Save(); return(1); } catch (Exception ex) { return(0); } }
/// <summary> /// Issue Book /// </summary> /// <param name="issue"></param> /// <returns></returns> public int IssueBook(Transaction issue) { tbl_Transaction tbl_transaction = new tbl_Transaction(); using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { var searchbook = unitOfWorks.BookRepository.GetByID(book => book.BookId == issue.BookId && book.AvailStatus == true); if (searchbook != null) { tbl_transaction.BookId = issue.BookId; tbl_transaction.DueDate = issue.DueDate; tbl_transaction.IssueDate = issue.IssueDate; tbl_transaction.ReturnDate = issue.ReturnDate; tbl_transaction.TransactionId = issue.TransactionId; tbl_transaction.UserId = issue.UserId; unitOfWorks.TransactionRepository.Insert(tbl_transaction); unitOfWorks.Save(); var UpdateBook = unitOfWorks.BookRepository.GetByID(Book => Book.BookId == tbl_transaction.BookId); UpdateBook.AvailStatus = false; unitOfWorks.Save(); return(1); } else { return(0); } } catch (Exception ex) { return(-99); } }
/// <summary> /// Return Book /// </summary> /// <param name="returnBook"></param> /// <returns></returns> public int ReturnBook(Transaction returnBook) { tbl_Transaction tbl_transaction = new tbl_Transaction(); using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { var searchbook = unitOfWorks.BookRepository.GetByID(book => book.BookId == returnBook.BookId && book.AvailStatus == false); if (searchbook != null) { var transaction = unitOfWorks.TransactionRepository.GetByID(book => book.BookId == returnBook.BookId && book.ReturnDate == null); transaction.ReturnDate = returnBook.ReturnDate; unitOfWorks.Save(); var UpdateBook = unitOfWorks.BookRepository.GetByID(Book => Book.BookId == transaction.BookId); UpdateBook.AvailStatus = true; unitOfWorks.Save(); return(1); } else { return(0); } } catch (Exception ex) { return(0); } }
private void btnLogin_Click(object sender, EventArgs e) { if (BaseValidator.IsFormValid(this.components)) { using (var uow = new UnitOfWorks()) { if (IsEdit) { var id = Common.Common.UserID; var user = uow.Userrepository.GetById(id); user.Username = txtUsername.Text; user.userPassword = txtPassword.Text; uow.Userrepository.Update(user); uow.Save(); Application.Restart(); } else { if (uow.Userrepository.GetAll(l => l.Username == txtUsername.Text && l.userPassword == txtPassword.Text).Any()) { Common.Common.UserID = uow.Userrepository.GetAll(l => l.Username == txtUsername.Text && l.userPassword == txtPassword.Text).Select(u => u.UserID).SingleOrDefault(); DialogResult = DialogResult.OK; } else { RtlMessageBox.Show("اطلاعات وارد شده صحیح نمی باشد", "هشدار", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } }
public void Delete() { try { UnitOfWorks unitOfWorks = new UnitOfWorks(new QLNSSGU_1Entities()); int row_handle = _view.GVDanhGiaVienChuc.FocusedRowHandle; if (row_handle >= 0) { int id = Convert.ToInt32(_view.GVDanhGiaVienChuc.GetFocusedRowCellDisplayText("Id")); DialogResult dialogResult = XtraMessageBox.Show("Bạn có chắc chắn muốn xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult == DialogResult.Yes) { unitOfWorks.QuaTrinhDanhGiaVienChucRepository.DeleteById(id); unitOfWorks.Save(); _view.GVDanhGiaVienChuc.DeleteRow(row_handle); Refresh(); } } else { XtraMessageBox.Show("Vui lòng chọn dòng cần xóa.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { XtraMessageBox.Show("Không thể xóa. Quá trình đánh giá này đang được sử dụng.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void UpdateData() { UnitOfWorks unitOfWorks = new UnitOfWorks(new QLNSSGU_1Entities()); int id = Convert.ToInt32(_view.GVDanhGiaVienChuc.GetFocusedRowCellDisplayText("Id")); DateTime? ngaybatdau = DateTimeHelper.ParseDatetimeMatchDatetimeDatabase(_view.DTNgayBatDau.Text); DateTime? ngayketthuc = DateTimeHelper.ParseDatetimeMatchDatetimeDatabase(_view.DTNgayKetThuc.Text); QuaTrinhDanhGiaVienChuc quaTrinhDanhGia = unitOfWorks.QuaTrinhDanhGiaVienChucRepository.GetObjectById(id); if (khoangThoiGianChanged) { quaTrinhDanhGia.idDanhMucThoiGian = Convert.ToInt32(_view.CBXKhoangThoiGian.EditValue); khoangThoiGianChanged = false; } if (ngayBatDauChanged) { quaTrinhDanhGia.ngayBatDau = ngaybatdau; ngayBatDauChanged = false; } if (ngayKetThucChanged) { quaTrinhDanhGia.ngayKetThuc = ngayketthuc; ngayKetThucChanged = false; } if (mucDoDanhGiaChanged) { quaTrinhDanhGia.idMucDoDanhGia = Convert.ToInt32(_view.CBXMucDoDanhGia.EditValue); mucDoDanhGiaChanged = false; } unitOfWorks.Save(); LoadGridTabPageDanhGiaVienChuc(_view.TXTMaVienChuc.Text); XtraMessageBox.Show("Sửa dữ liệu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void btnSave_Click(object sender, EventArgs e) { if (BaseValidator.IsFormValid(this.components)) { if (rbPayment.Checked || rbRecieve.Checked) { var accounting = new DataLayer.Context.Accounting() { CustomerID_Cus = int.Parse(dgvTransAction.CurrentRow.Cells[1].Value.ToString()), AccountingDescription = txtDescription.Text, TypeID_typ = (rbRecieve.Checked) ? 2 : 1, Amount = txtAmount.Text.ToString(), CreationDate = DateTime.Now }; using (var uow = new UnitOfWorks()) { if (accountingId == 0) { uow.AccountingRepo.Insert(accounting); } else { accounting.AccountigID = accountingId; uow.AccountingRepo.Update(accounting); } uow.Save(); }; DialogResult = DialogResult.OK; } else { RtlMessageBox.Show("لطفا نوع تراکنش را انتخاب کنید"); } } }
private void DeleteCustomer_Click(object sender, EventArgs e) { if (dgvCustomer.CurrentRow != null) { using (var uow = new UnitOfWorks()) { var name = dgvCustomer.CurrentRow.Cells[1].Value.ToString(); if (RtlMessageBox.Show($"آیا از حذف {name} مطمئن هستید؟" , "توجه" , MessageBoxButtons.YesNo , MessageBoxIcon.Warning) == DialogResult.Yes ) { int customerId = int.Parse(dgvCustomer.CurrentRow.Cells[0].Value.ToString()); uow.CustomerRepository.Delete(customerId); uow.Save(); BindGrid(); } } } else { RtlMessageBox.Show("لطفا شخصی را انتخاب کنید"); } }
/// <summary> /// Update Member details /// </summary> /// <param name="users"></param> /// <returns></returns> public int UpdateMemberDetails(Users users) { tbl_Users tbl_users = new tbl_Users(); using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { // tbl_Users updateMember = tbl_Users.Single(User => User.userId == userId); tbl_users.DOB = users.DOB; tbl_users.EmailId = users.EmailId; tbl_users.FirstName = users.FirstName; tbl_users.LastName = users.LastName; tbl_users.MobileNo = users.MobileNo; tbl_users.Password = users.Password; tbl_users.RoleId = users.RoleId; tbl_users.UserId = users.UserId; unitOfWorks.UserRepository.Update(tbl_users); unitOfWorks.Save(); return(1); } catch (Exception ex) { return(0); } }
/// <summary> /// Update Book /// </summary> /// <param name="books"></param> /// <returns></returns> public int UpdateBook(Books books) { tbl_Books updateBook = new tbl_Books(); using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { updateBook.Author = books.Author; updateBook.AvailStatus = books.AvailStatus; updateBook.Category = books.Category; updateBook.Description = books.Description; updateBook.ISBNNumber = books.Description; updateBook.Title = books.Title; updateBook.Price = books.Price; updateBook.Publisher = books.Publisher; updateBook.BookId = books.BookId; unitOfWorks.BookRepository.Update(updateBook); unitOfWorks.Save(); return(1); } catch (Exception ex) { return(0); } }
private void btnAddCustomer_Click(object sender, EventArgs e) { if (BaseValidator.IsFormValid(this.components)) { string imageName = Guid.NewGuid().ToString() + Path.GetExtension(pcCustomer.ImageLocation); string imagePath = Application.StartupPath + "/Images/Customers/"; if (!Directory.Exists(imagePath)) { Directory.CreateDirectory(imagePath); } pcCustomer.Image.Save(imagePath + imageName); Customers customer = new Customers() { FullName = txtFullName.Text.ToString(), Email = txtEmail.Text.ToString(), CustomerAddress = txtAddress.Text.ToString(), CustomerImage = imageName, Mobile = txtMobile.Text.ToString() }; using (var uof = new UnitOfWorks()) { if (customerID == 0) { uof.CustomerRepository.InsertCustomers(customer); } else { customer.CustomerID = customerID; uof.CustomerRepository.Update(customer); } uof.Save(); } DialogResult = DialogResult.OK; } }
/// <summary> /// Add Category /// </summary> /// <param name="categories"></param> /// <returns></returns> public int AddCategory(Categories categories) { tbl_Category tbl_category = new tbl_Category(); using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { var result = unitOfWorks.CategoryRepository.GetByID(x => x.Category == categories.Category); if (result == null) { tbl_category.Category = categories.Category; //tbl_category.CategoryId = categories.CategoryId; unitOfWorks.CategoryRepository.Insert(tbl_category); unitOfWorks.Save(); return(1); } else { return(0); } } catch (Exception ex) { return(-99); } }
/// <summary> /// Add Book /// </summary> /// <param name="books"></param> /// <returns></returns> public int AddBook(Books books) { tbl_Books tbl_books = new tbl_Books(); using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { tbl_books.Author = books.Author; tbl_books.AvailStatus = books.AvailStatus; //tbl_books.BookId = books.BookId; tbl_books.Category = books.Category; tbl_books.Description = books.Description; tbl_books.ISBNNumber = books.ISBNNumber; tbl_books.Title = books.Title; tbl_books.Price = books.Price; tbl_books.Publisher = books.Publisher; tbl_books.AvailStatus = true; unitOfWorks.BookRepository.Insert(tbl_books); unitOfWorks.Save(); return(1); } catch (Exception ex) { return(0); } }
public string AddStudent(StudentDTO studentDto) { Student student = new Student(); student.StudentId = studentDto.StudentId; student.Studentname = studentDto.Studentname; try { unitofworks.StudentRopository.Insert(student); unitofworks.Save(); return(message); } catch (Exception ex) { return(ex.Message); } }
/// <summary> /// Delete Member /// </summary> /// <param name="userID"></param> /// <returns></returns> public int DeleteMember(int userID) { using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { var result = unitOfWorks.TransactionRepository.GetDetailsbyUserId(userID).ToList(); if (result != null) { //var transaction = unitOfWorks.TransactionRepository.GetByID(user => user.UserId == userID && user.ReturnDate != null); //if (transaction != null) //{ // unitOfWorks.TransactionRepository.Delete(transaction.TransactionId); // unitOfWorks.UserRepository.Delete(userID); // unitOfWorks.Save(); // return 1; //} result.ToList().ForEach(c => { Transaction transaction = new Transaction(); { transaction.TransactionId = c.TransactionId; unitOfWorks.TransactionRepository.Delete(transaction.TransactionId); unitOfWorks.Save(); } }); } unitOfWorks.UserRepository.Delete(userID); unitOfWorks.Save(); return(1); } catch (Exception ex) { return(-99); } }
private void btnDelete_Click(object sender, EventArgs e) { if (dgvReport.CurrentRow != null) { var id = int.Parse(dgvReport.CurrentRow.Cells[0].Value.ToString()); if (RtlMessageBox.Show("آیا از حذف مطمئن هستید؟", "توجه", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (var uow = new UnitOfWorks()) { uow.AccountingRepo.Delete(id); uow.Save(); Filter(); } } } }
private void InsertData() { string mavienchuc = _view.TXTMaVienChuc.Text; UnitOfWorks unitOfWorks = new UnitOfWorks(new QLNSSGU_1Entities()); unitOfWorks.QuaTrinhDanhGiaVienChucRepository.Insert(new QuaTrinhDanhGiaVienChuc { idVienChuc = unitOfWorks.VienChucRepository.GetIdVienChuc(mavienchuc), idDanhMucThoiGian = Convert.ToInt32(_view.CBXKhoangThoiGian.EditValue), ngayBatDau = DateTimeHelper.ParseDatetimeMatchDatetimeDatabase(_view.DTNgayBatDau.Text), ngayKetThuc = DateTimeHelper.ParseDatetimeMatchDatetimeDatabase(_view.DTNgayKetThuc.Text), idMucDoDanhGia = Convert.ToInt32(_view.CBXMucDoDanhGia.EditValue) }); unitOfWorks.Save(); LoadGridTabPageDanhGiaVienChuc(_view.TXTMaVienChuc.Text); XtraMessageBox.Show("Thêm dữ liệu thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); SetDefaultValueControl(); }
/// <summary> /// Add Member /// </summary> /// <param name="users"></param> /// <returns></returns> public int AddMember(Users users) { tbl_Users tbl_users = new tbl_Users(); using (IUnitOfWorks unitOfWorks = new UnitOfWorks()) try { tbl_users.DOB = users.DOB; tbl_users.EmailId = users.EmailId; tbl_users.FirstName = users.FirstName; tbl_users.LastName = users.LastName; tbl_users.MobileNo = users.MobileNo; tbl_users.Password = "******"; tbl_users.RoleId = users.RoleId; unitOfWorks.UserRepository.Insert(tbl_users); unitOfWorks.Save(); return(1); } catch (Exception ex) { return(0); } }