Ejemplo n.º 1
0
        /*Merchant*/
        public ResponeMerchantConfig Insert(MerchantConfigApiModels info)
        {
            ResponeMerchantConfig result = new ResponeMerchantConfig();

            using (NuWebContext cxt = new NuWebContext())
            {
                using (var transaction = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        var isExsitMerchant = cxt.G_POSAPIMerchantConfig.Any(x => x.POSAPIUrl.ToLower().Equals(info.POSAPIUrl.ToLower()));
                        if (isExsitMerchant)
                        {
                            NSLog.Logger.Info(string.Format("The merchant [{0}] already exist", info.POSAPIUrl));
                            return(result);
                        }

                        G_POSAPIMerchantConfig itemMerchantConfig = new G_POSAPIMerchantConfig();
                        /*string POSAPIMerchantConfigId =Guid.NewGuid().ToString();*/
                        string POSAPIMerchantConfigId = string.Empty;
                        if (string.IsNullOrEmpty(info.Id))
                        {
                            POSAPIMerchantConfigId = Guid.NewGuid().ToString();
                        }
                        else
                        {
                            POSAPIMerchantConfigId = info.Id;
                        }
                        itemMerchantConfig.Id            = POSAPIMerchantConfigId;
                        itemMerchantConfig.NuPOSInstance = info.NuPOSInstance;
                        itemMerchantConfig.POSAPIUrl     = info.POSAPIUrl;
                        itemMerchantConfig.FTPHost       = info.FTPHost;
                        itemMerchantConfig.FTPUser       = info.FTPUser;
                        itemMerchantConfig.FTPPassword   = info.FTPPassword;
                        itemMerchantConfig.ImageBaseUrl  = info.ImageBaseUrl;

                        itemMerchantConfig.BreakfastStart     = info.BreakfastStart;
                        itemMerchantConfig.BreakfastEnd       = info.BreakfastEnd;
                        itemMerchantConfig.LunchStart         = info.LunchStart;
                        itemMerchantConfig.LunchEnd           = info.LunchEnd;
                        itemMerchantConfig.DinnerStart        = info.DinnerStart;
                        itemMerchantConfig.DinnerEnd          = info.DinnerEnd;
                        itemMerchantConfig.CreatedDate        = DateTime.Now;
                        itemMerchantConfig.IsActived          = true;
                        itemMerchantConfig.POSInstanceVersion = info.POSInstanceVersion;

                        itemMerchantConfig.MorningStart = info.MorningStart;
                        itemMerchantConfig.MorningEnd   = info.MorningEnd;
                        itemMerchantConfig.MidDayStart  = info.MidDayStart;
                        itemMerchantConfig.MidDayEnd    = info.MidDayEnd;
                        List <G_POSEmployeeConfig> lstInsertEmployee = new List <G_POSEmployeeConfig>();
                        G_POSEmployeeConfig        itemEmpInsert     = null;
                        foreach (var item in info.ListEmployees)
                        {
                            itemEmpInsert = new G_POSEmployeeConfig();
                            if (string.IsNullOrEmpty(item.Id))
                            {
                                itemEmpInsert.Id = Guid.NewGuid().ToString();
                            }
                            else
                            {
                                itemEmpInsert.Id = item.Id;
                            }
                            //itemEmpInsert.Id = Guid.NewGuid().ToString();
                            itemEmpInsert.POSAPIMerchantConfigId = POSAPIMerchantConfigId;
                            itemEmpInsert.UserName    = item.UserName;
                            itemEmpInsert.Password    = CommonHelper.GetSHA512(item.Password);
                            itemEmpInsert.CreatedDate = DateTime.Now;
                            itemEmpInsert.IsActived   = true;
                            lstInsertEmployee.Add(itemEmpInsert);
                        }
                        cxt.G_POSAPIMerchantConfig.Add(itemMerchantConfig);
                        cxt.G_POSEmployeeConfig.AddRange(lstInsertEmployee);
                        cxt.SaveChanges();
                        transaction.Commit();

                        result.IsOk         = true;
                        result.POSIntanceID = itemMerchantConfig.Id;

                        NSLog.Logger.Info("Insert [Insert Pos Api Merchant Config] data success", info);
                    }
                    catch (Exception ex)
                    {
                        NSLog.Logger.Error("Insert [Insert Pos Api Merchant Config] data fail", ex);
                        //_logger.Error(ex);
                        result.IsOk = false;
                        transaction.Rollback();
                    }
                    finally
                    {
                        if (cxt != null)
                        {
                            cxt.Dispose();
                        }
                    }
                }
            }
            //var jsonContent = JsonConvert.SerializeObject(info);
            //_baseFactory.InsertTrackingLog("G_POSAPIMerchantConfig", jsonContent, info.NuPOSInstance, result);

            return(result);
        }
Ejemplo n.º 2
0
        //2018-01-02
        public ResponeMerchantConfig RegisterAccountFromCSC(MerchantConfigApiModels info)
        {
            ResponeMerchantConfig result = new ResponeMerchantConfig();

            using (NuWebContext cxt = new NuWebContext())
            {
                using (var transaction = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        var merchant = cxt.G_POSAPIMerchantConfig.Where(x => x.POSAPIUrl == info.POSAPIUrl && x.IsActived).FirstOrDefault();
                        if (merchant != null)
                        {
                            List <G_POSEmployeeConfig> lstInsertEmployee = new List <G_POSEmployeeConfig>();
                            G_POSEmployeeConfig        itemEmpInsert     = null;
                            foreach (var item in info.ListEmployees)
                            {
                                itemEmpInsert = new G_POSEmployeeConfig();
                                if (string.IsNullOrEmpty(item.Id))
                                {
                                    itemEmpInsert.Id = Guid.NewGuid().ToString();
                                }
                                else
                                {
                                    itemEmpInsert.Id = item.Id;
                                }
                                itemEmpInsert.POSAPIMerchantConfigId = merchant.Id;
                                itemEmpInsert.UserName    = item.UserName;
                                itemEmpInsert.Password    = item.Password;
                                itemEmpInsert.CreatedDate = DateTime.Now;
                                itemEmpInsert.IsActived   = true;
                                lstInsertEmployee.Add(itemEmpInsert);
                            }
                            cxt.G_POSEmployeeConfig.AddRange(lstInsertEmployee);
                        }
                        else
                        {
                            G_POSAPIMerchantConfig itemMerchantConfig = new G_POSAPIMerchantConfig();

                            itemMerchantConfig.Id            = info.Id;
                            itemMerchantConfig.NuPOSInstance = info.NuPOSInstance;
                            itemMerchantConfig.POSAPIUrl     = info.POSAPIUrl;
                            itemMerchantConfig.FTPHost       = info.FTPHost;
                            itemMerchantConfig.FTPUser       = info.FTPUser;
                            itemMerchantConfig.FTPPassword   = info.FTPPassword;
                            itemMerchantConfig.ImageBaseUrl  = info.ImageBaseUrl;

                            itemMerchantConfig.BreakfastStart     = info.BreakfastStart;
                            itemMerchantConfig.BreakfastEnd       = info.BreakfastEnd;
                            itemMerchantConfig.LunchStart         = info.LunchStart;
                            itemMerchantConfig.LunchEnd           = info.LunchEnd;
                            itemMerchantConfig.DinnerStart        = info.DinnerStart;
                            itemMerchantConfig.DinnerEnd          = info.DinnerEnd;
                            itemMerchantConfig.CreatedDate        = DateTime.Now;
                            itemMerchantConfig.IsActived          = true;
                            itemMerchantConfig.POSInstanceVersion = info.POSInstanceVersion;

                            itemMerchantConfig.MorningStart = info.MorningStart;
                            itemMerchantConfig.MorningEnd   = info.MorningEnd;
                            itemMerchantConfig.MidDayStart  = info.MidDayStart;
                            itemMerchantConfig.MidDayEnd    = info.MidDayEnd;
                            List <G_POSEmployeeConfig> lstInsertEmployee = new List <G_POSEmployeeConfig>();
                            G_POSEmployeeConfig        itemEmpInsert     = null;
                            foreach (var item in info.ListEmployees)
                            {
                                itemEmpInsert = new G_POSEmployeeConfig();
                                if (string.IsNullOrEmpty(item.Id))
                                {
                                    itemEmpInsert.Id = Guid.NewGuid().ToString();
                                }
                                else
                                {
                                    itemEmpInsert.Id = item.Id;
                                }
                                //itemEmpInsert.Id = Guid.NewGuid().ToString();
                                itemEmpInsert.POSAPIMerchantConfigId = info.Id;
                                itemEmpInsert.UserName    = item.UserName;
                                itemEmpInsert.Password    = item.Password;
                                itemEmpInsert.CreatedDate = DateTime.Now;
                                itemEmpInsert.IsActived   = true;
                                lstInsertEmployee.Add(itemEmpInsert);
                            }
                            cxt.G_POSAPIMerchantConfig.Add(itemMerchantConfig);
                            cxt.G_POSEmployeeConfig.AddRange(lstInsertEmployee);
                        }
                        cxt.SaveChanges();
                        transaction.Commit();

                        result.IsOk         = true;
                        result.POSIntanceID = info.Id;

                        NSLog.Logger.Info("Insert [RegisterAccountFromCSC] data success", info);
                    }
                    catch (Exception ex)
                    {
                        NSLog.Logger.Error("Insert [RegisterAccountFromCSC] data fail", ex);
                        //_logger.Error(ex);
                        result.IsOk = false;
                        transaction.Rollback();
                    }
                    finally
                    {
                        if (cxt != null)
                        {
                            cxt.Dispose();
                        }
                    }
                }
            }

            return(result);
        }