/// <summary> /// Create/Update MobileBriefcase data /// </summary> /// <param name="objId"></param> /// <param name="data"></param> /// <param name="staffId"></param> /// <param name="briefcaseType"></param> public static void CreateUpdateBriefcase(int objId,object data, int staffId, int briefcaseType) { if (data != null) { if (!_ctx.MobileBriefcase.Any(b => b.BreifcaseTypeId == objId && b.StaffId == staffId && b.BreifcaseType == briefcaseType)) { MobileBriefcase bc = new Data.MobileBriefcase(); bc.BreifcaseType = briefcaseType; bc.BreifcaseTypeId = objId; bc.BriefcaseData = Newtonsoft.Json.JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented); bc.StaffId = staffId; bc.CreatedBy = GetCurrentUser(staffId); bc.CreatedDate = DateTime.Now; bc.ModifiedBy = GetCurrentUser(staffId); bc.ModifiedDate = DateTime.Now; _ctx.MobileBriefcase.Add(bc); _ctx.SaveChanges(); } else { var obj = _ctx.MobileBriefcase.Where(b => b.BreifcaseTypeId == objId && b.StaffId == staffId && b.BreifcaseType == briefcaseType) .FirstOrDefault(); obj.BriefcaseData = Newtonsoft.Json.JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.Indented); _ctx.SaveChanges(); } } }
/// <summary> /// Save MyPreference Screen Data. /// </summary> /// <param name="stf"></param> /// <param name="loggedInUser"></param> /// <returns></returns> public async Task <_SCResult <Models.StaffPreferenceModel> > Save(StaffPreferences stf, int loggedInUser) { try { var _Ce = new _SCResult <Models.StaffPreferenceModel>(); IBriefcaseRepository _repo = new BriefcaseRepositiry(new SCMobile()); List <Difference> differences = new List <Difference>(); bool modified = IsDataModified(stf.StaffPreferenceId, loggedInUser, CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "MYPREFERENCE"), stf, out differences); if (modified) { var original = _scEntity.StaffPreferences .Where(s => s.StaffPreferenceId == stf.StaffPreferenceId).FirstOrDefault(); foreach (var difference in differences) { string[] changedPprts = difference.PropertyName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); //Handled only objects which doesn't have sibling object if (string.IsNullOrEmpty(difference.ParentPropertyName)) { foreach (PropertyInfo propertyInfo in original.GetType().GetProperties()) { if (changedPprts.Contains(propertyInfo.Name)) { propertyInfo.SetValue(original, propertyInfo.GetValue(stf, null), null); } } } } _scEntity.SaveChanges(); } _Ce.SavedResult = await _repo.GetMyPreference(stf.StaffId); _Ce.LocalstoreName = "mypreference"; _Ce.UnsavedId = _Ce.SavedId = _Ce.SavedResult.StaffPreferenceId; _Ce.DeleteUnsavedChanges = true; _Ce.ShowDetails = false; _Ce.Details = null; _Ce.SavedResult = await FindMobileUser(stf.StaffId); if (stf != null) { CommonFunctions <Models.StaffPreferenceModel> .CreateUpdateBriefcase(stf.StaffPreferenceId, _Ce.SavedResult, loggedInUser, CommonDBFunctions.GetGlobalCodeId("BRIEFCASETYPE", "MYPREFERENCE")); } return(_Ce); } catch (Exception ex) { Exception excep = new Exception("Exception occured in MobileStaffRepositiry.Save method." + ex.Message); throw excep; } }
/// <summary> /// UpdateSignature /// </summary> /// <param name="sig"></param> /// <returns></returns> public _SCResult <ClientDocumentsModel> UpdateSignature(ClientDocumentsModel sig) { var _Ce = new _SCResult <ClientDocumentsModel>(); if (!string.IsNullOrEmpty(sig.Signature.SignatureString)) { //1 _sqlConnection = new SqlConnection(_ctx.Database.Connection.ConnectionString); _sqlConnection.Open(); _sqlTransaction = _sqlConnection.BeginTransaction(IsolationLevel.ReadUncommitted, "_sqlTransaction"); sig.Signature.SignatureString = sig.Signature.SignatureString.Replace("data:image/png;base64,", ""); var signatureImageBytes = Convert.FromBase64String(SC.Base.CommonFunctions.EncodeBase64(sig.Signature.SignatureString)); //var path = "C:\\Users\\pradeepa\\AppData\\Local\\Microsoft\\Windows\\INetCache\\test123.jpeg"; //System.Drawing.Image newImage; //using (MemoryStream stream = new MemoryStream(signatureImageBytes)) //{ // newImage = System.Drawing.Image.FromStream(stream, true); // newImage.Save(path); // //img.Attributes.Add("src", strFileName); //} ScreenModel sModel = _commonRepository.GetScreenDetail(sig.DocumentCodeId); var userCode = _ctx.Documents .Where(d => d.DocumentId == sig.DocumentId) .Select(d => d.ModifiedBy).FirstOrDefault(); var ClientId = sig.IsClient == "Y" ? sig.ClientId : 0; SignedByClient(ClientId, sig.DocumentId, signatureImageBytes, sig.SignatureId, sig.DocumentVersionId, userCode, _sqlTransaction); DataSet dataset = ExecuteUpdateStoredProcedure(_sqlTransaction, sModel.PostUpdateStoredProcedure, sig.DocumentId, sig.AuthorId, userCode, ""); if (dataset.Tables.Count > 0 && dataset.Tables["PostUpdateErrorDetails"].Rows.Count > 0) { _sqlTransaction.Rollback(); _Ce.NoteValidationMessages = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(dataset)); } else { _sqlTransaction.Commit(); DocumentPDFGenerationQueue queue = new DocumentPDFGenerationQueue(); queue.DocumentPDFGenerationQueueId = -1; queue.CreatedBy = "APIDocumentRepository"; queue.CreatedDate = DateTime.Now; queue.ModifiedBy = "APIDocumentRepository"; queue.ModifiedDate = DateTime.Now; queue.DocumentVersionId = Convert.ToInt32(sig.DocumentVersionId); _ctx.DocumentPDFGenerationQueue.Add(queue); _ctx.SaveChanges(); _Ce.SavedResult = GetDocumentModel(sig.DocumentVersionId); _Ce.DeleteObjectStoreData = true; _Ce.DeleteUnsavedChanges = true; _Ce.SavedId = _Ce.SavedResult.DocumentVersionId; _Ce.UnsavedId = _Ce.SavedResult.DocumentVersionId; } //Call SignDocument Function //1. Convert Signature String to Bytes //2. Call SignedbyClient //3. Pass DocumentId and get ssp_SCGetDocumentDetailOfDocumentID Documents table data using ssp_SCGetDocumentDetailOfDocumentID (TNOT REQUIRED) - Get CurrentUser From Modified By ModifiedBy //4. Call ssp_SCSignatureSignedByClient passig parameters Transaction //5. Call DocumentPostSignatureUpdates- StaffId,DocumentId,Transaction, //6. Call DocumentPostSignatureUpdates ssp_SCDocumentPostSignatureUpdates Pass UserId and DocumentId //7. Call ExceutePostUpdateScreenStoredProcedureCore GetSP name from Screens.PostUpdateScreenStoredProcedureCore for the DocumentCodeId and rerurn PostUpdateErrorDetails Table //8. If record found in PostUpdateErrorDetails, Rollback transaction Otherwise call ExecuteUpdateStoredProcedure With Screens .PostUpdateStoredProcedure. //9. If records found PostUpdateErrorDetails in Rollback Otherwise Commit } return(_Ce); }