public EnquiryBooking Insert(EnquiryBooking objEnquiryBooking) { using (IDbConnection connection = OpenConnection(dataConnection)) { var result = new EnquiryBooking(); IDbTransaction trn = connection.BeginTransaction(); string sql = @"INSERT INTO EnquiryBooking(EnquiryRef,EnquiryDate,EnquiryClient,ClientTypeId,ModeofContactId,ProjectTypeId, EnquiryReference,EnquiryContactNo,EnquiryEmail,EnquiryLocation,EnquiryDetails,EnquiryCancel,CreatedBy,CreatedDate,OrganizationId) VALUES(@EnquiryRef,@EnquiryDate,@EnquiryClient,@ClientTypeId,@ModeofContactId,@ProjectTypeId,@EnquiryReference, @EnquiryContactNo,@EnquiryEmail,@EnquiryLocation,@EnquiryDetails,0,@CreatedBy,@CreatedDate,@OrganizationId); SELECT CAST(SCOPE_IDENTITY() as int)"; try { int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(EnquiryBooking).Name, "0", 1); objEnquiryBooking.EnquiryRef = internalid.ToString(); int id = connection.Query <int>(sql, objEnquiryBooking, trn).Single(); objEnquiryBooking.EnquiryId = id; InsertLoginHistory(dataConnection, objEnquiryBooking.CreatedBy, "Create", "EnquiryBooking", id.ToString(), "0"); trn.Commit(); } catch (Exception ex) { trn.Rollback(); objEnquiryBooking.EnquiryId = 0; objEnquiryBooking.EnquiryRef = null; } return(objEnquiryBooking); } }
public SubContractor Insert(SubContractor objSubContractor) { using (IDbConnection connection = OpenConnection(dataConnection)) { var result = new SubContractor(); IDbTransaction trn = connection.BeginTransaction(); string sql = @"INSERT INTO SubContractor(SubRefNo,SubName,ContactPerson,Designation,OfficeNo,MobileNo,Email, Address1,Address2,Address3,Address4,CreatedBy,CreatedDate,OrganizationId) VALUES(@SubRefNo,@SubName,@ContactPerson,@Designation,@OfficeNo,@MobileNo,@Email,@Address1, @Address2,@Address3,@Address4,@CreatedBy,@CreatedDate,@OrganizationId); SELECT CAST(SCOPE_IDENTITY() as int)"; try { int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(SubContractor).Name, "0", 1); objSubContractor.SubRefNo = internalid.ToString(); int id = connection.Query <int>(sql, objSubContractor, trn).Single(); objSubContractor.SubContractorId = id; InsertLoginHistory(dataConnection, objSubContractor.CreatedBy, "Create", "Subcontractor", id.ToString(), "0"); trn.Commit(); } catch (Exception ex) { trn.Rollback(); objSubContractor.SubContractorId = 0; objSubContractor.SubRefNo = null; } return(objSubContractor); } }
public string GetRefNo(EnquiryBooking objEnquiryBooking) { using (IDbConnection connection = OpenConnection(dataConnection)) { string RefNo = ""; var result = new EnquiryBooking(); IDbTransaction trn = connection.BeginTransaction(); try { int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(EnquiryBooking).Name, "0", 0); RefNo = internalid.ToString(); trn.Commit(); } catch (Exception ex) { trn.Rollback(); } return(RefNo); } }
public Projects Insert(Projects objProjects) { using (IDbConnection connection = OpenConnection(dataConnection)) { var result = new Projects(); IDbTransaction trn = connection.BeginTransaction(); string sql = @"INSERT INTO Project(ProjectRefNo,ProjectDate,ClientId,ProjectEnquiry,ProjectOrderRefNo,CreatedBy,CreatedDate,EnquiryId) VALUES(@ProjectRefNo,@ProjectDate,@ClientId,@ProjectEnquiry,@ProjectOrderRefNo,@CreatedBy,@CreatedDate,@EnquiryId); SELECT CAST(SCOPE_IDENTITY() as int)"; try { int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(Projects).Name, "0", 1); objProjects.ProjectRefNo = internalid.ToString(); int id = connection.Query <int>(sql, objProjects, trn).Single(); objProjects.ProjectId = id; foreach (var ProjectTask in objProjects.ProjectTask) { if ((ProjectTask.MileStoneName == null)) { continue; } new ProjectItemRepository().InsertProjectTask(new ProjectTask { ProjectId = id, MileStoneName = ProjectTask.MileStoneName, TaskName = ProjectTask.TaskName, StartDate = ProjectTask.StartDate, EndDate = ProjectTask.EndDate }, connection, trn); } foreach (var ProjectPaymentSchedule in objProjects.ProjectPaymentSchedule) { if ((ProjectPaymentSchedule.Description == null)) { continue; } new PaymentScheduleItemRepository().InsertProjectPaymentSchedule(new ProjectPaymentSchedule { ProjectId = id, Paymentid = ProjectPaymentSchedule.Paymentid, Date = ProjectPaymentSchedule.Date, Description = ProjectPaymentSchedule.Description, Percentage = ProjectPaymentSchedule.Percentage, Amount = ProjectPaymentSchedule.Amount }, connection, trn); } InsertLoginHistory(dataConnection, objProjects.CreatedBy, "Create", "Project", id.ToString(), "0"); trn.Commit(); } catch (Exception ex) { trn.Rollback(); objProjects.ProjectId = 0; objProjects.ProjectRefNo = null; } return(objProjects); } }