public async Task <int> Add(DistributionEmployee employee)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(employee);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
        public async Task <int> Add(FarmerRetailerOrderItems item)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(item);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 3
0
        public async Task <int> InsertDevice(UserAccountDevice userAccountDevice)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(userAccountDevice);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 4
0
        public async Task <int> AddAsync(UI.Captions.Models.Caption caption)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(caption);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
        public async Task <int> AddItemAsync(PurchaseOrderItem poItem)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(poItem);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
        public async Task <int> Add(FarmerBuyingCalendar farmerBuyingCalendar)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(farmerBuyingCalendar);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
        public async Task <int> Add(FertilizerCategory fertilizerCategory)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(fertilizerCategory);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 8
0
        public async Task <int> AddAsync(ProductLanguage productLanguage)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(productLanguage);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
        public async Task <int> Add(CollectionInventoryHistory history)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(history);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 10
0
        public async Task <int> AddLocation(RetailerLocation retailerLocation)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(retailerLocation);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 11
0
        public async Task <int> AddItems(FulfillmentCollectionItem fulCoItem)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(fulCoItem);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
        public async Task <int> Add(FulfillmentFROrderViewModel fulFr)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(fulFr);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 13
0
        public async Task <int> CreateTripAudit(TripAudit audit)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(audit);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
        public async Task <int> AddAsync(GrowingMethod growingMethod)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(growingMethod);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 15
0
        public async Task <int> AddAsync(Message msg, CancellationToken cancellationToken = default(CancellationToken))
        {
            msg.Code = await _storageQueries.GenarateCodeAsync(StorageKeys.MessageCode);

            var cmd = QueriesCreatingHelper.CreateQueryInsert(msg);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 16
0
        public async Task <int> AddAsync(string key)
        {
            var storage = new Storage()
            {
                Key           = key,
                NumericLength = 3,
                Prefix        = "",
                Value         = 1,
                HasDate       = false,
            };
            var cmd = QueriesCreatingHelper.CreateQueryInsert(storage);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
Esempio n. 17
0
        public async Task <int> AddOrUpdateContact(Contact contact)
        {
            var cmd = string.Empty;

            if (contact.Id != 0)
            {
                cmd = QueriesCreatingHelper.CreateQueryUpdate(contact);
                var rs = await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection);

                return(rs == 0 ? -1 : contact.Id);
            }
            else
            {
                cmd  = QueriesCreatingHelper.CreateQueryInsert(contact);
                cmd += ";SELECT LAST_INSERT_ID();";
                return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
            }
        }
Esempio n. 18
0
        public async Task <int> AddOrUpdateLanguage(CategoryLanguage language)
        {
            string cmd  = QueriesCreatingHelper.CreateQuerySelect <CategoryLanguage>($"category_id = {language.CategoryId} AND language_id = {language.LanguageId}");
            var    lang = (await DALHelper.ExecuteQuery <CategoryLanguage>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).FirstOrDefault();

            if (lang == null)
            {
                cmd  = QueriesCreatingHelper.CreateQueryInsert(language);
                cmd += ";SELECT LAST_INSERT_ID();";
                return(await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection));
            }
            else
            {
                language.Id = lang.Id;
                cmd         = QueriesCreatingHelper.CreateQueryUpdate(language);
                var rs = await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection);

                return(rs == 0 ? -1 : language.Id);
            }
        }
Esempio n. 19
0
        public async Task <int> Write(UserSession userLogin, T value, IDbConnection conn = null, IDbTransaction trans = null)
        {
            Assembly assembly = null;

            if (!string.IsNullOrEmpty(GlobalConfiguration.IntegrationTemplate.ModelAssembly))
            {
                var path = Path.Combine(Directory.GetCurrentDirectory(), "ExtensionFolder", GlobalConfiguration.IntegrationTemplate.ModelAssembly);
                assembly = Assembly.Load(File.ReadAllBytes(path));
            }
            EventResultModel eventResultModel = null;

            if (conn != null && trans != null)
            {
                try
                {
                    var model = GlobalConfiguration.IntegrationTemplate.ModelTemplates.FirstOrDefault(m => m.Name == typeof(T).Name);

                    // run berore record event
                    eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.BeforeRowEvent, typeof(BaseEvent <T>), new object[] { this, value, conn, trans, userLogin });
                    if (!eventResultModel.Result)
                    {
                        throw new Exception(eventResultModel.ErrorMessage);
                    }
                    if (!eventResultModel.IsBubble)
                    {
                        return(0);
                    }

                    string cmd = QueriesCreatingHelper.CreateQueryInsert(value);

                    var rs = await DALHelper.Execute(cmd, dbTransaction : trans, connection : conn);

                    // run after record event
                    eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.AfterRowEvent, typeof(BaseEvent <T>), new object[] { this, value, conn, trans, userLogin });
                    if (!eventResultModel.Result)
                    {
                        throw new Exception(eventResultModel.ErrorMessage);
                    }
                    if (!eventResultModel.IsBubble)
                    {
                        return(0);
                    }

                    return(rs == 1 ? 0 : -1);
                }
                catch (Exception ex)
                {
                    LogHelper.GetLogger().Error(ex.Message);
                    return(-1);
                }
            }
            else
            {
                try
                {
                    var model = GlobalConfiguration.IntegrationTemplate.ModelTemplates.FirstOrDefault(m => m.Name == typeof(T).Name);

                    // run berore record event
                    eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.BeforeRowEvent, typeof(BaseEvent <T>), new object[] { this, value, conn, trans, userLogin });
                    if (!eventResultModel.Result)
                    {
                        throw new Exception(eventResultModel.ErrorMessage);
                    }
                    if (!eventResultModel.IsBubble)
                    {
                        return(0);
                    }

                    string cmd = QueriesCreatingHelper.CreateQueryInsert(value);

                    var rs = await DALHelper.Execute(cmd);

                    // run after record event
                    eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.AfterRowEvent, typeof(BaseEvent <T>), new object[] { this, value, conn, trans, userLogin });
                    if (!eventResultModel.Result)
                    {
                        throw new Exception(eventResultModel.ErrorMessage);
                    }
                    if (!eventResultModel.IsBubble)
                    {
                        return(0);
                    }

                    return(rs == 1 ? 0 : -1);
                }
                catch (Exception ex)
                {
                    LogHelper.GetLogger().Error(ex.Message);
                    return(-1);
                }
            }
        }
Esempio n. 20
0
        public async Task <int> WriteArray(UserSession user, IEnumerable <T> value, IDbConnection conn = null, IDbTransaction trans = null)
        {
            Assembly assembly = null;

            if (!string.IsNullOrEmpty(GlobalConfiguration.IntegrationTemplate.ModelAssembly))
            {
                var path = Path.Combine(Directory.GetCurrentDirectory(), "ExtensionFolder", GlobalConfiguration.IntegrationTemplate.ModelAssembly);
                assembly = Assembly.Load(File.ReadAllBytes(path));
            }
            EventResultModel eventResultModel = null;

            if (conn != null && trans != null)
            {
                try
                {
                    var model = GlobalConfiguration.IntegrationTemplate.ModelTemplates.FirstOrDefault(m => m.Name == typeof(T).Name);

                    // run berore event
                    eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.BeforeEvent, typeof(BaseEvent <T>), new object[] { this, value, conn, trans, user });
                    if (!eventResultModel.Result)
                    {
                        throw new Exception(eventResultModel.ErrorMessage);
                    }
                    if (!eventResultModel.IsBubble)
                    {
                        return(0);
                    }

                    foreach (var item in value)
                    {
                        // run berore record event
                        eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.BeforeRowEvent, typeof(BaseEvent <T>), new object[] { this, item, conn, trans, user });
                        if (!eventResultModel.Result)
                        {
                            throw new Exception(eventResultModel.ErrorMessage);
                        }
                        if (!eventResultModel.IsBubble)
                        {
                            continue;
                        }

                        string cmd = QueriesCreatingHelper.CreateQueryInsert(value);

                        var rs = await DALHelper.Execute(cmd, dbTransaction : trans, connection : conn);

                        // run after record event
                        eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.AfterRowEvent, typeof(BaseEvent <T>), new object[] { this, item, conn, trans, user });
                        if (!eventResultModel.Result)
                        {
                            throw new Exception(eventResultModel.ErrorMessage);
                        }
                        if (!eventResultModel.IsBubble)
                        {
                            continue;
                        }
                    }

                    // run after event
                    eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.AfterEvent, typeof(BaseEvent <T>), new object[] { this, value, conn, trans, user });
                    if (!eventResultModel.Result)
                    {
                        throw new Exception(eventResultModel.ErrorMessage);
                    }
                    if (!eventResultModel.IsBubble)
                    {
                        return(0);
                    }

                    return(0);
                }
                catch (Exception ex)
                {
                    LogHelper.GetLogger().Error(ex.Message);
                    return(-1);
                }
            }
            else
            {
                using (conn = DALHelper.GetConnection())
                {
                    conn.Open();
                    using (trans = conn.BeginTransaction())
                    {
                        try
                        {
                            var model = GlobalConfiguration.IntegrationTemplate.ModelTemplates.FirstOrDefault(m => m.Name == typeof(T).Name);

                            // run berore event
                            eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.BeforeEvent, typeof(BaseEvent <T>), new object[] { this, value, conn, trans, user });
                            if (!eventResultModel.Result)
                            {
                                throw new Exception(eventResultModel.ErrorMessage);
                            }
                            if (!eventResultModel.IsBubble)
                            {
                                return(0);
                            }

                            foreach (var item in value)
                            {
                                // run berore record event
                                eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.BeforeRowEvent, typeof(BaseEvent <T>), new object[] { this, item, conn, trans, user });
                                if (!eventResultModel.Result)
                                {
                                    throw new Exception(eventResultModel.ErrorMessage);
                                }
                                if (!eventResultModel.IsBubble)
                                {
                                    continue;
                                }

                                string cmd = QueriesCreatingHelper.CreateQueryInsert(value);

                                var rs = await DALHelper.Execute(cmd, dbTransaction : trans, connection : conn);

                                // run after record event
                                eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.AfterRowEvent, typeof(BaseEvent <T>), new object[] { this, item, conn, trans, user });
                                if (!eventResultModel.Result)
                                {
                                    throw new Exception(eventResultModel.ErrorMessage);
                                }
                                if (!eventResultModel.IsBubble)
                                {
                                    continue;
                                }
                            }

                            // run after event
                            eventResultModel = CommonHelper.RunEvent(assembly, model.Insert.AfterEvent, typeof(BaseEvent <T>), new object[] { this, value, conn, trans, user });
                            if (!eventResultModel.Result)
                            {
                                throw new Exception(eventResultModel.ErrorMessage);
                            }
                            if (!eventResultModel.IsBubble)
                            {
                                return(0);
                            }

                            trans.Commit();
                            return(0);
                        }
                        catch (Exception ex)
                        {
                            LogHelper.GetLogger().Error(ex.Message);
                            try
                            {
                                trans.Rollback();
                            }
                            catch { }
                            return(-1);
                        }
                        finally
                        {
                            if (conn.State == System.Data.ConnectionState.Open)
                            {
                                conn.Close();
                            }
                        }
                    }
                }
            }
        }