Beispiel #1
0
        public ActionResult <Definition> Post([FromBody] Definition definition)
        {
            definition.User = _currentUserAccessor.GetCurrentUser;
            definition.Id   = _dictionaryDbContext.Definitions.Max(x => x.Id) + 1;
            _dictionaryDbContext.Definitions.Add(definition);
            var inserted = _dictionaryDbContext.SaveChanges() == 1;

            if (inserted)
            {
                return(Ok(definition));
            }

            return(BadRequest());
        }
        public static async Task PopulateDictionaries(IApplicationBuilder app)
        {
            DictionaryDbContext context = app.ApplicationServices.GetRequiredService <DictionaryDbContext>();

            if (!context.DocumentTypes.Any(dt => dt.DocumentKind == DocumentKind.SalesOrder))
            {
                context.DocumentTypes.Add(new DocumentType {
                    Code = "SportsStore.SalesOrder", Symbol = "ZS", Name = "Zamówienie sprzedaży", DocumentKind = DocumentKind.SalesOrder
                });
            }

            if (!context.DocumentTypes.Any(dt => dt.DocumentKind == DocumentKind.Receipt))
            {
                context.DocumentTypes.Add(new DocumentType {
                    Code = "SportsStore.Receipt", Symbol = "PAR", Name = "Paragon", DocumentKind = DocumentKind.Receipt
                });
            }

            if (!context.DocumentTypes.Any(dt => dt.DocumentKind == DocumentKind.SalesInvoice))
            {
                context.DocumentTypes.Add(new DocumentType {
                    Code = "SportsStore.SalesInvoice", Symbol = "FS", Name = "Faktura sprzedaży", DocumentKind = DocumentKind.SalesInvoice
                });
            }

            if (!context.VatRates.Any())
            {
                context.VatRates.Add(new VatRate {
                    Symbol = "A", Value = 0.23m
                });
            }

            context.SaveChanges();
        }
        public dynamic DeleteVatRate(int vatRateId)
        {
            if (vatRateId == 0)
            {
                return new { Message = "" }
            }
            ;

            if (_productRepository.Products.Any(p => p.VatRateId == vatRateId) && _orderRepository.Orders.Any(p => p.VatRateId == vatRateId))
            {
                return new { Result = false, Message = "Stawka VAT została już wykorzystana w aplikacji" }
            }
            ;

            var vatRate = GetVatRate(vatRateId);

            _context.VatRates.Remove(vatRate);

            _context.SaveChanges();
            return(new { Result = true, Message = "Stawka VAT została usunięta" });
        }
        public int SaveDocumentType(DocumentType documentType)
        {
            if (documentType.DocumentTypeId == 0)
            {
                _context.Add(documentType);
            }
            else
            {
                var dbEntry = _context.DocumentTypes.FirstOrDefault(dt => dt.DocumentTypeId == documentType.DocumentTypeId);

                if (dbEntry != null)
                {
                    dbEntry.Code   = documentType.Code;
                    dbEntry.Symbol = documentType.Symbol;
                    dbEntry.Name   = documentType.Name;
                }
            }

            _context.SaveChanges();

            return(documentType.DocumentTypeId);
        }
        public ActionResult Register([FromBody] User user)
        {
            var selectedUser = _dictionaryDbContext.Users.FirstOrDefault(x => x.Email == user.Email);

            if (selectedUser != null)
            {
                return(BadRequest());
            }

            user.Password  = HashPassword(user.Password);
            user.IsActive  = true;
            user.CreatedOn = DateTime.UtcNow;
            _dictionaryDbContext.Users.Add(user);
            var created = _dictionaryDbContext.SaveChanges() == 1;

            if (created)
            {
                return(CreatedAtAction("Get", new { id = user.Id }, new { Email = user.Email, Id = user.Id, CreatedOn = DateTime.UtcNow }));
            }

            return(BadRequest());
        }
        public async Task AddWords(Dictionary dictionary)
        {
            await _context.Dictionaries.AddAsync(dictionary);

            _context.SaveChanges();
        }