private async Task SaveToLocalDB(MobileFormData data, FormSaveResponse response, int rowId)
        {
            try
            {
                LastSyncInfo syncInfo = App.Settings.SyncInfo;
                if (syncInfo.LastOfflineSaveTs > DateTime.Now)
                {
                    response.Message = "Sync required. Device date time is incorrect.";
                }
                else
                {
                    List <DbParameter> dbParameters = new List <DbParameter>();

                    string query = data.GetQuery(dbParameters, rowId);

                    int rowAffected = App.DataDB.DoNonQuery(query, dbParameters.ToArray());
                    int lastRowId   = (rowId != 0) ? rowId : Convert.ToInt32(App.DataDB.DoScalar($"SELECT MAX(id) FROM {TableName}"));
                    response.PushResponse = new PushResponse()
                    {
                        RowId = lastRowId
                    };

                    if (HasFileSelect && rowAffected > 0)
                    {
                        if (lastRowId > 0)
                        {
                            await WriteFilesToLocal(lastRowId);
                        }
                    }

                    response.Status = rowAffected > 0;

                    if (response.Status)
                    {
                        response.Message = "Data stored locally :)";
                        App.Settings.SyncInfo.LastOfflineSaveTs = DateTime.Now;
                        await Store.SetJSONAsync(AppConst.LAST_SYNC_INFO, App.Settings.SyncInfo);
                    }
                    else
                    {
                        throw new Exception("Failed to store data locally");
                    }
                }
            }
            catch (Exception ex)
            {
                response.Message = "Failed to store data locally";

                EbLog.Error("Exception at [EbMobileForm] while [SaveToLocalDB] method : " + ex.Message);
            }
        }
        private async Task SaveToCloudDB(MobileFormData data, FormSaveResponse response, int rowId, string pageRefId)
        {
            try
            {
                WebformData webFormData = data.ToWebFormData();

                foreach (MobileTable table in data.Tables)
                {
                    if (table.Files.Any())
                    {
                        table.InitFilesToUpload();

                        bool status = await this.SendAndFillFupData(webFormData, table);

                        if (!status)
                        {
                            throw new Exception("Image Upload faild, breaking form save");
                        }
                    }
                }

                int locid = App.Settings.CurrentLocId;

                EbLog.Info($"saving record in location {locid}");

                PushResponse pushResponse = await FormService.Instance.SendFormDataAsync(pageRefId, webFormData, rowId, this.WebFormRefId, locid);

                this.LogPushResponse(pushResponse);

                if (pushResponse.RowAffected > 0)
                {
                    response.Status       = true;
                    response.Message      = "Saved successfully :)";
                    response.PushResponse = pushResponse;
                }
                else
                {
                    throw new Exception(pushResponse.Message);
                }
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = ex.Message;
                EbLog.Error(ex.Message);
            }
        }
        public async Task <FormSaveResponse> Save(int rowId, string pageRefId)
        {
            FormSaveResponse response = new FormSaveResponse();

            try
            {
                MobileFormData data = await this.GetFormData(rowId);

                data.SortByMaster();

                if (NetworkType == NetworkMode.Online)
                {
                    await this.SaveToCloudDB(data, response, rowId, pageRefId);
                }
                else if (NetworkType == NetworkMode.Offline)
                {
                    await this.SaveToLocalDB(data, response, rowId);
                }
                else
                {
                    if (Utils.HasInternet)
                    {
                        await this.SaveToCloudDB(data, response, rowId, pageRefId);
                    }
                    else
                    {
                        await this.SaveToLocalDB(data, response, rowId);
                    }
                }
            }
            catch (Exception ex)
            {
                EbLog.Error("Error in [EbMobileForm.Save] " + ex.Message);
            }
            return(response);
        }