Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddMemoryCache();
            var appSettings = Configuration.GetSection("AppSettings").Get <AppSettings>();
            var connections = Configuration.GetSection("ConnectionStrings").Get <ConnectionStrings>();

            services.AddDbContext <MainDataContext>(options =>
            {
                var connection = new SqlConnection(connections.Main);
                options.UseSqlServer(connection);
            });
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            TranslateUtility.SetHttpContext(services.BuildServiceProvider().GetService <IHttpContextAccessor>());
            // In production, the Angular files will be served from this directory
            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddScoped <IDataRepositoryFactory, DataRepositoriesFactory>();

            //New instance for injection
            services.AddTransient(typeof(IBase <>), typeof(Repository <>));
        }
Beispiel #2
0
        public override Result <User> Update(User entity)
        {
            try
            {
                var dbEntity = _Context.Users.Find(entity.UserId);
                _Context.Entry <User>(dbEntity).State = EntityState.Detached;
                if (entity.Password != dbEntity.Password)
                {
                    entity.Password = MD5.Encrypt(entity.Password, _appSettings.Value.TokenKey);
                }
                var translation = dbEntity as IEntityTranslate;
                if (translation != null)
                {
                    entity.TranslationData = TranslateUtility.SaveTranslation(entity, translation.TranslationData);
                }
                _Context.Users.Attach(entity);
                _Context.Entry <User>(entity).State = EntityState.Modified;

                _Context.SaveChanges();

                return(new Result <User>(entity.Id, 0, "OK", new List <User>()
                {
                    entity
                }));
            }

            catch (Exception ex)
            {
                return(new Result <User>(-1, -1, ex.Message, null, ex));
            }
        }
Beispiel #3
0
        public virtual Result <T> Update(T entity)
        {
            try
            {
                var dbEntity = _DbSet.Find(entity.Id);
                _Context.Entry <T>(dbEntity).State = EntityState.Detached;
                var translation = dbEntity as IEntityTranslate;
                if (translation != null)
                {
                    entity.TranslationData = TranslateUtility.SaveTranslation(entity, translation.TranslationData);
                }
                _DbSet.Attach(entity);
                _Context.Entry <T>(entity).State = EntityState.Modified;

                _Context.SaveChanges();

                return(new Result <T>(entity.Id, 0, "OK", new List <T>()
                {
                    entity
                }));
            }

            catch (Exception ex)
            {
                return(new Result <T>(-1, -1, ex.Message, null, ex));
            }
        }
Beispiel #4
0
        public static string UpdateTranslate(List <string> strings)
        {
#if USE_GOOGLE_API
            return(TranslateUtility.DownloadAndReloadTranslate());
#endif

            return("google api disable");
        }
        public override Result <Product> Update(Product entity)
        {
            Result <Product> result = new Result <Product>(-1, -1, "error_msg");

            using (var transaction = _Context.Database.BeginTransaction())
            {
                try
                {
                    var dbEntity = _Context.Products.Find(entity.Id);
                    _Context.Entry <Product>(dbEntity).State = EntityState.Detached;
                    var translation = dbEntity as IEntityTranslate;
                    if (translation != null)
                    {
                        entity.TranslationData = TranslateUtility.SaveTranslation(entity, translation.TranslationData);
                    }
                    var costs = entity.SuppliersCosts?.ToList();
                    var units = entity.ProductUnits?.ToList();
                    var taxes = entity.Taxes?.ToList();
                    var bases = entity.BaseCompositeProducts?.ToList();
                    entity.BaseCompositeProducts = null;
                    entity.SuppliersCosts        = null;
                    entity.ProductUnits          = null;
                    entity.Sequence = string.IsNullOrEmpty(entity.Sequence)? _sequenceRepo.CreateSequence(Common.Enums.SequenceTypes.Products):entity.Sequence;
                    entity.Taxes    = null;
                    decimal tempCost = (entity.IsService ? bases.Sum(x => x.TotalCost) : costs.Sum(x => x.Cost) / costs.Count);
                    entity.Cost = entity.Cost > tempCost ? entity.Cost : tempCost;
                    decimal tempPrice = (entity.IsService ? bases.Sum(x => x.TotalPrice) : entity.Price);
                    entity.Price = entity.Price == 0 ? tempPrice : entity.Price;
                    _Context.Products.Update(entity);
                    _Context.SaveChanges();

                    SetChildren(entity, costs, units, taxes, bases);


                    transaction.Commit();
                    result = new Result <Product>(0, 0, "ok_msg", new List <Product>()
                    {
                        new Product()
                        {
                            Id = entity.Id
                        }
                    });
                }
                catch (Exception ex)
                {
                    result = new Result <Product>(-1, -1, $"error_msg", null, ex);
                    transaction.Rollback();
                }
            }
            return(result);
        }
Beispiel #6
0
        public virtual Result <T> Add(T entity)
        {
            try
            {
                var translation = entity as IEntityTranslate;
                if (translation != null)
                {
                    entity.TranslationData = TranslateUtility.SaveTranslation(entity, translation.TranslationData);
                }
                _Context.Set <T>().Add(entity);

                _Context.SaveChanges();

                return(new Result <T>(entity.Id, 0, "OK", new List <T>()
                {
                    entity
                }));;
            }

            catch (Exception ex)
            {
                return(new Result <T>(-1, -1, ex.Message, null, ex));
            }
        }
Beispiel #7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers(mvcOptions =>
            {
                mvcOptions.EnableEndpointRouting = false;
            });
            services.AddOData();
            services.AddMemoryCache();
            var appSettings = Configuration.GetSection("AppSettings").Get <AppSettings>();
            var connections = Configuration.GetSection("ConnectionStrings").Get <ConnectionStrings>();

            services.AddDbContext <MainDataContext>(options =>
            {
                var connection = new SqlConnection(connections.Main);
                options.UseSqlServer(connection);
            });
            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            TranslateUtility.SetHttpContext(services.BuildServiceProvider().GetService <IHttpContextAccessor>());
            services.AddSingleton <IFileProvider>(
                new PhysicalFileProvider(
                    Path.Combine(Directory.GetCurrentDirectory(), "")));

            services.AddScoped <IBranchOfficeRepository, BranchOfficeRepository>();
            services.AddScoped <ICashRegisterOpeningRepository, CashRegisterOpeningRepository>();
            services.AddScoped <IRoleSectionOperationRepository, RoleSectionOperationRepository>();
            services.AddScoped <ISellerRepository, SellerRepository>();
            services.AddScoped <ISequenceManagerRepository, SequenceManagerRepository>();
            services.AddScoped <ICompanyPaymentRepository, CompanyPaymentRepository>();
            services.AddScoped <ILanguageKeyRepository, LanguageKeyRepository>();
            services.AddScoped <IBusinessStateRepository, BusinessStateRepository>();
            services.AddScoped <ICompositeProductRepository, CompositeProductRepository>();
            services.AddScoped <ICreditNoteRepository, CreditNoteRepository>();
            services.AddScoped <ICustomerBalanceRepository, CustomerBalanceRepository>();
            services.AddScoped <ICustomerPaymentRepository, CustomerPaymentRepository>();
            services.AddScoped <IExpenseRepository, ExpenseRepository>();
            services.AddScoped <IExpensesPaymentRepository, ExpensesPaymentRepository>();
            services.AddScoped <IInventoryEntryRepository, InventoryEntryRepository>();
            services.AddScoped <IExpenseTaxRepository, ExpenseTaxRepository>();
            services.AddScoped <IInventoryRepository, InventoryRepository>();
            services.AddScoped <IInvoiceDetailRepository, InvoiceDetailRepository>();
            services.AddScoped <IInvoiceRepository, InvoiceRepository>();
            services.AddScoped <IInvoiceTaxRepository, InvoiceTaxRepository>();
            services.AddScoped <IProductRepository, ProductRepository>();
            services.AddScoped <IProductTaxRepository, ProductTaxRepository>();
            services.AddScoped <ISupplierReturnRepository, SupplierReturnRepository>();
            services.AddScoped <IUnitProductEquivalenceRepository, UnitProductEquivalenceRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IWarehouseMovementRepository, WarehouseMovementRepository>();
            services.AddScoped <IWarehouseRepository, WarehouseRepository>();
            services.AddScoped <IWarehouseTransferRepository, WarehouseTransferRepository>();

            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddScoped <IDataRepositoryFactory, DataRepositoriesFactory>();

            //New instance for injection
            services.AddTransient(typeof(IBase <>), typeof(Repository <>));
            // Add Culture
            //var cultureInfo = new CultureInfo("es-DO");
            //CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
            //CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
                          options.TokenValidationParameters = new TokenValidationParameters
            {
                ValidateIssuer           = true,
                ValidateAudience         = true,
                ValidateLifetime         = true,
                ValidateIssuerSigningKey = true,
                ValidIssuer      = appSettings.Domain,
                ValidAudience    = appSettings.Domain,
                IssuerSigningKey = new SymmetricSecurityKey(
                    Encoding.UTF8.GetBytes(appSettings.TokenKey)),
                ClockSkew = TimeSpan.Zero
            });

            services.AddCors(o => o.AddPolicy("AllowAllOrigins", builder =>
            {
                builder.AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader();
            }));

            services.AddControllers().AddNewtonsoftJson(options =>
                                                        options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                                                        );
        }