private void employeeModelAddButton_Click(object sender, EventArgs e) { ServiceResult <Employee> result = employeeService.validate(this.employeeModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.insert(employeeService .initialize(this.employeeModel).model, typeof(Employee)); if (dbResult.isOk()) { Employee employee = this.employeeModel; BindingList <EmployeeModel> newList = (BindingList <EmployeeModel>) this.employeesSet.DataSource; newList.Add(new EmployeeModel(employee.id, employee.fullname, employee.dob, employee.address, employee.phone, employee.title.name)); this.employeesSet.DataSource = newList; this.employeeModel = new Employee(); this.renderModel(); } }
public DatabaseOperationResult ChangePassword(ChangePasswordViewModel model) { var result = new DatabaseOperationResult(); if (string.IsNullOrWhiteSpace(model.NewPassword)) { result.AddError("Password is not provided"); return result; } var user = _unitOfWork.UserRepository.FindById(_sessionWrapper.UserId); if (user == null) { result.AddError("User not found"); return result; } string oldPassword = _webHelper.EncryptToMd5(model.OldPassword); bool oldPasswordIsValid = oldPassword == user.Password; if (!oldPasswordIsValid) result.AddError("Old password doesn't match."); if (oldPasswordIsValid) { user.Password = _webHelper.EncryptToMd5(model.NewPassword); _unitOfWork.UserRepository.Update(user); _unitOfWork.Save(); } return result; }
public DatabaseOperationResult InsertRecord(InitialBorrowerParameters inParams) { var spParams = new InitialBorrowerInfo() { credit_quality_id = inParams.CreditQualityId, email = inParams.Email, first_name = inParams.FirstName, last_name = inParams.LastName, loan_amount = inParams.LoanAmount, loan_type_id = inParams.LoanTypeId, phone_number = inParams.PhoneNumber, property_value = inParams.PropertyValue, referring_officer_id = inParams.ReferringOfficerId, created_dt = DateTime.Now }; _db.InitialBorrowerInfoes.Add(spParams); var returnVal = new DatabaseOperationResult(); returnVal.RecordsAffected = _db.SaveChanges(); returnVal.IsSuccessful = returnVal.RecordsAffected == 1; return(returnVal); }
private void customerModelAddButton_Click(object sender, EventArgs e) { ServiceResult <Customer> result = customerService.validate(this.customerModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.insert(customerService .initialize(this.customerModel).model, customerType); if (dbResult.isOk()) { BindingList <CustomerModel> list = (BindingList <CustomerModel>) this.customerSet.DataSource; Customer customer = this.customerModel; list.Add(new CustomerModel(customer.id, customer.fullname, customer.dob, customer.address, customer.email, customer.expiredDate, customer.debt)); this.customerSet.DataSource = list; this.customerModel = new Customer(); this.renderModel(); } }
private void bookModelAddButton_Click(object sender, EventArgs e) { ServiceResult <Book> result = bookService.validate(this.bookModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.insert(bookService .initialize(this.bookModel).model, type); if (dbResult.isOk()) { BindingList <Book> list = (BindingList <Book>) this.bookSet.DataSource; list.Add(this.bookModel); this.bookSet.DataSource = list; this.bookModel = new Book(); this.renderModel(); } }
public DatabaseOperationResult ChangePassword(ChangePasswordViewModel model) { var result = new DatabaseOperationResult(); if (string.IsNullOrWhiteSpace(model.NewPassword)) { result.AddError("Password is not provided"); return(result); } var user = _unitOfWork.UserRepository.FindById(_sessionWrapper.UserId); if (user == null) { result.AddError("User not found"); return(result); } string oldPassword = _webHelper.EncryptToMd5(model.OldPassword); bool oldPasswordIsValid = oldPassword == user.Password; if (!oldPasswordIsValid) { result.AddError("Old password doesn't match."); } if (oldPasswordIsValid) { user.Password = _webHelper.EncryptToMd5(model.NewPassword); _unitOfWork.UserRepository.Update(user); _unitOfWork.Save(); } return(result); }
private void bookModelRemoveButton_Click(object sender, EventArgs e) { DatabaseOperationResult dbResult = dao.delete(this.bookModel, type); if (dbResult.isOk()) { BindingList <Book> list = (BindingList <Book>) this.bookSet.DataSource; list.Remove(this.bookSet.CurrentRow.DataBoundItem as Book); this.bookSet.DataSource = list; this.bookModel = new Book(); this.bookModel.price = 1; this.renderModel(); } }
private void customerModelRemoveButton_Click(object sender, EventArgs e) { if (this.customerSet.SelectedRows.Count == 0) { return; } DatabaseOperationResult dbResult = dao.delete(this.customerModel, customerType); if (dbResult.isOk()) { BindingList <CustomerModel> list = (BindingList <CustomerModel>) this.customerSet.DataSource; list.Remove(this.customerSet.CurrentRow.DataBoundItem as CustomerModel); this.customerSet.DataSource = list; this.customerModel = new Customer(); this.renderModel(); } }
private void employeeModelRemoveButton_Click(object sender, EventArgs e) { if (this.employeesSet.SelectedRows.Count == 0) { return; } DataGridViewRow row = this.employeesSet.SelectedRows[0]; EmployeeModel model = row.DataBoundItem as EmployeeModel; this.employeesSet.Rows.Remove(row); DatabaseOperationResult dbResult = dao.delete(this.employeeModel, typeof(Employee)); if (dbResult.isOk()) { this.employeeModel = new Employee(); this.renderModel(); } }
public DatabaseOperationResult insert(PaymentReceipt receipt) { using (TransactionScope transactionScope = new TransactionScope()) { DatabaseOperationResult result = new DatabaseOperationResult(); DatabaseOperationResult lendingReceiptInsertionResult = dao.insert(receipt.lendingReceipt, typeof(LendingReceipt)); if (!lendingReceiptInsertionResult.isOk()) { result.status = ServiceStatus.INVALID; result.message = "Operation failed when trying to insert Lending Receipt"; return(result); } DatabaseOperationResult paymentReceiptInsertionResult = dao.insert(receipt, typeof(PaymentReceipt)); if (!paymentReceiptInsertionResult.isOk()) { result.status = ServiceStatus.INVALID; result.message = "Operation failed when trying to insert Payment Receipt"; return(result); } DatabaseOperationResult lendingDetailsInsertionResult; foreach (LendingReceiptDetail detail in receipt.lendingReceipt.details) { lendingDetailsInsertionResult = dao.insert(detail, typeof(LendingReceiptDetail)); if (!lendingDetailsInsertionResult.isOk()) { result.status = ServiceStatus.INVALID; result.message = "Operation failed when trying to insert Lending details"; return(result); } } transactionScope.Complete(); return(result); } }
private void customerModelEditButton_Click(object sender, EventArgs e) { if (this.customerSet.SelectedRows.Count == 0) { return; } ServiceResult <Customer> result = customerService.validate(this.customerModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.update(this.customerModel, customerType); if (dbResult.isOk()) { DataGridViewRow row = this.customerSet.CurrentRow; row.Cells["ID"].Value = this.customerModel.id; row.Cells["Fullname"].Value = this.customerModel.fullname; row.Cells["Birthdate"].Value = this.customerModel.dob; row.Cells["Address"].Value = this.customerModel.address; row.Cells["Email"].Value = this.customerModel.email; row.Cells["Expiry date"].Value = this.customerModel.expiredDate; row.Cells["Debt amount"].Value = this.customerModel.debt; this.customerModel = new Customer(); this.renderModel(); } }
public DatabaseOperationResult RegisterUser(RegisterViewModel model) { var result = new DatabaseOperationResult(); model.Email = model.Email.Trim(); if (this.FindUserByEmail(model.Email) != null) { result.AddError("The email has already been taken."); return(result); } if (this.FindUserByUsername(model.Username) != null) { result.AddError("The username has already been taken."); return(result); } var encryptedPassword = _webHelper.EncryptToMd5(model.Password); var currentIpAddress = _webHelper.GetCurrentIpAddress(); var getUserRole = _unitOfWork.UserRoleRepository.Table() .FirstOrDefault(x => x.Name == SystemUserRoleNames.User); if (getUserRole == null) { result.AddError("User acceptance is currently off, please contact to administrator."); return(result); } _unitOfWork.UserRepository.Insert(new User { Email = model.Email.Trim(), IPAddress = currentIpAddress, LastActivity = System.DateTime.Now, Password = encryptedPassword, Username = model.Username, UserRoleId = getUserRole.Id }); _unitOfWork.Save(); return(result); }
private void employeeModelEditButton_Click(object sender, EventArgs e) { if (this.employeesSet.SelectedRows.Count == 0) { return; } ServiceResult <Employee> result = employeeService.validate(this.employeeModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.update(this.employeeModel, typeof(Employee)); if (dbResult.isOk()) { Employee employee = this.employeeModel; DataGridViewRow row = this.employeesSet.CurrentRow; row.Cells["ID"].Value = employee.id; row.Cells["Fullname"].Value = employee.fullname; row.Cells["Birthdate"].Value = employee.dob; row.Cells["Address"].Value = employee.address; row.Cells["Phone"].Value = employee.phone; row.Cells["Title"].Value = employee.title.name; this.employeeModel = new Employee(); this.renderModel(); } }
private void submitLendingButton_Click(object sender, EventArgs e) { this.paymentReceipt.lendingReceipt.details = this.lendingDetails; ServiceResult <PaymentReceipt> result = paymentReceiptService.initialize(this.paymentReceipt); if (!result.isOk()) { this.renderErrors(result.messages); return; } this.paymentReceipt = result.model; result = paymentReceiptService.validate(this.paymentReceipt); if (!result.isOk()) { this.renderErrors(result.messages); return; } DatabaseOperationResult insertResult = paymentReceiptService.insert(this.paymentReceipt); if (!insertResult.isOk()) { return; } this.paymentReceipt = new PaymentReceipt(); this.renderBookSet(); this.customerModel = new Customer(); this.renderCustomerModel(); this.itemSetClearButton_Click(sender, e); this.employeeSet_SelectedIndexChanged(this.employeeSet, e); }
private void bookModelEditButton_Click(object sender, EventArgs e) { ServiceResult <Book> result = bookService.validate(this.bookModel); if (!result.isOk()) { String message = ""; foreach (String val in result.messages.Values) { message += $"\n{val}"; } MessageBox.Show(message.Substring(1, message.Length - 1), "Invalid information", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DatabaseOperationResult dbResult = dao.update(this.bookModel, type); if (dbResult.isOk()) { DataGridViewRow row = this.bookSet.CurrentRow; row.Cells["ID"].Value = this.bookModel.id; row.Cells["Name"].Value = this.bookModel.name; row.Cells["Author"].Value = this.bookModel.author; row.Cells["Publisher"].Value = this.bookModel.publisher; row.Cells["Published date"].Value = this.bookModel.publishDate; row.Cells["Price"].Value = this.bookModel.price; row.Cells["Stocked date"].Value = this.bookModel.stockedDate; this.bookModel = new Book(); this.bookModel.price = 1; this.renderModel(); } }
public DatabaseOperationResult WallpaperInsert(WallpaperViewModel model) { var result = new DatabaseOperationResult(); if (model.file == null && model.file.ContentLength == 0) { result.AddError("File not found!"); return result; } if (((model.file.ContentLength / 1024) / 1024) > 2) { result.AddError("File must be less than 2 MB"); return result; } System.Drawing.Image resolution = System.Drawing.Image.FromStream(model.file.InputStream); if (resolution.Width < 1024 || resolution.Height < 768) { result.AddError("The file must be greater than 1024 pixels wide and greater than to 768 pixels tall at least."); return result; } var fileExtension = System.IO.Path.GetExtension(model.file.FileName); var allowedExtensions = new List<string> { ".jpg", ".jpeg", ".tiff", ".png" }; if (!string.IsNullOrWhiteSpace(fileExtension)) fileExtension = fileExtension.ToLowerInvariant(); else { result.AddError("The file extension not provided. Please try again"); return result; } if (!allowedExtensions.Contains(fileExtension)) { result.AddError("The file extension not supported, allowed extension is \"*.jpg\", \"*.jpeg\", \"*.tiff\""); return result; } if (!System.IO.Directory.Exists(System.Web.Hosting.HostingEnvironment.MapPath("/Uploads"))) System.IO.Directory.CreateDirectory(System.Web.Hosting.HostingEnvironment.MapPath("/Uploads")); var lastWallpaper = _unitOfWork.WallpaperRepository.Table().OrderByDescending(x => x.Id).FirstOrDefault(); string fileName = lastWallpaper == null ? "walltage-1" : "walltage-" + (lastWallpaper.Id + 1); model.ImgPath = string.Format("{0}{1}", fileName, fileExtension); string filePath = System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads"), model.ImgPath); var tagList = PrepareTagList(model.Tags); model.Name = System.IO.Path.GetFileNameWithoutExtension(model.file.FileName); _unitOfWork.WallpaperRepository.Insert(new Domain.Entities.Wallpaper { AddedBy = _sessionWrapper.UserName, AddedDate = DateTime.Now, CategoryId = model.CategoryId, ImgPath = model.ImgPath, Name = model.Name, ResolutionId = model.ResolutionId, Size = model.file.ContentLength, UploaderId = _sessionWrapper.UserId, TagList = tagList }); _unitOfWork.Save(true); if (!System.IO.File.Exists(filePath)) { model.file.SaveAs(filePath); if (!System.IO.Directory.Exists(System.Web.Hosting.HostingEnvironment.MapPath("/Uploads/Thumbs"))) System.IO.Directory.CreateDirectory(System.Web.Hosting.HostingEnvironment.MapPath("/Uploads/Thumbs")); System.Drawing.Image image = System.Drawing.Image.FromFile(filePath); image = _webHelper.CreateThumbnail(image, new System.Drawing.Size(256, 250), true); image.Save(System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads/Thumbs/") + fileName); image.Dispose(); } return result; }
public DatabaseOperationResult WallpaperInsert(WallpaperViewModel model) { var result = new DatabaseOperationResult(); if (model.file == null && model.file.ContentLength == 0) { result.AddError("File not found!"); return(result); } if (((model.file.ContentLength / 1024) / 1024) > 2) { result.AddError("File must be less than 2 MB"); return(result); } System.Drawing.Image resolution = System.Drawing.Image.FromStream(model.file.InputStream); if (resolution.Width < 1024 || resolution.Height < 768) { result.AddError("The file must be greater than 1024 pixels wide and greater than to 768 pixels tall at least."); return(result); } var fileExtension = System.IO.Path.GetExtension(model.file.FileName); var allowedExtensions = new List <string> { ".jpg", ".jpeg", ".tiff", ".png" }; if (!string.IsNullOrWhiteSpace(fileExtension)) { fileExtension = fileExtension.ToLowerInvariant(); } else { result.AddError("The file extension not provided. Please try again"); return(result); } if (!allowedExtensions.Contains(fileExtension)) { result.AddError("The file extension not supported, allowed extension is \"*.jpg\", \"*.jpeg\", \"*.tiff\""); return(result); } if (!System.IO.Directory.Exists(System.Web.Hosting.HostingEnvironment.MapPath("/Uploads"))) { System.IO.Directory.CreateDirectory(System.Web.Hosting.HostingEnvironment.MapPath("/Uploads")); } var lastWallpaper = _unitOfWork.WallpaperRepository.Table().OrderByDescending(x => x.Id).FirstOrDefault(); string fileName = lastWallpaper == null ? "walltage-1" : "walltage-" + (lastWallpaper.Id + 1); model.ImgPath = string.Format("{0}{1}", fileName, fileExtension); string filePath = System.IO.Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads"), model.ImgPath); var tagList = PrepareTagList(model.Tags); model.Name = System.IO.Path.GetFileNameWithoutExtension(model.file.FileName); _unitOfWork.WallpaperRepository.Insert(new Domain.Entities.Wallpaper { AddedBy = _sessionWrapper.UserName, AddedDate = DateTime.Now, CategoryId = model.CategoryId, ImgPath = model.ImgPath, ResolutionId = model.ResolutionId, Size = model.file.ContentLength, UploaderId = _sessionWrapper.UserId, TagList = tagList }); _unitOfWork.Save(true); if (!System.IO.File.Exists(filePath)) { model.file.SaveAs(filePath); if (!System.IO.Directory.Exists(System.Web.Hosting.HostingEnvironment.MapPath("/Uploads/Thumbs"))) { System.IO.Directory.CreateDirectory(System.Web.Hosting.HostingEnvironment.MapPath("/Uploads/Thumbs")); } System.Drawing.Image image = System.Drawing.Image.FromFile(filePath); image = _webHelper.CreateThumbnail(image, new System.Drawing.Size(256, 250), true); image.Save(System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads/Thumbs/") + fileName); image.Dispose(); } return(result); }
public DatabaseOperationResult RegisterUser(RegisterViewModel model) { var result = new DatabaseOperationResult(); model.Email = model.Email.Trim(); if (this.FindUserByEmail(model.Email) != null) { result.AddError("The email has already been taken."); return result; } if (this.FindUserByUsername(model.Username) != null) { result.AddError("The username has already been taken."); return result; } var encryptedPassword = _webHelper.EncryptToMd5(model.Password); var currentIpAddress = _webHelper.GetCurrentIpAddress(); var getUserRole = _unitOfWork.UserRoleRepository.Table() .FirstOrDefault(x => x.Name == SystemUserRoleNames.User); if (getUserRole == null) { result.AddError("User acceptance is currently off, please contact to administrator."); return result; } _unitOfWork.UserRepository.Insert(new User { Email = model.Email.Trim(), IPAddress = currentIpAddress, LastActivity = System.DateTime.Now, Password = encryptedPassword, Username = model.Username, UserRoleId = getUserRole.Id }); _unitOfWork.Save(); return result; }