Esempio n. 1
0
        public async Task AddNewTern(int userId, FormCollection collection)
        {
            var tern = new GrowingFruitComings()
            {
                User          = _usersRepository.Get().FirstOrDefault(i => i.Id == userId),
                GrowingType   = _growingTypeRepository.Get().FirstOrDefault(i => i.Name == "Tern"),
                LandingDate   = DateTime.Parse(collection[1]),
                FloweringDate = DateTime.Parse(collection[2]),
                CultureType   = collection[3],
                Name          = collection[4],
                MassType      = collection[5],
                CurrencyType  = collection[6],
                Cost          = Convert.ToDecimal(collection[7].Replace(".", ",")),
                Amount        = Convert.ToDecimal(collection[8].Replace(".", ",")),
                Document      = FileNameValidator(collection[9])
            };

            _growingFruitComingsRepository.Add(tern);
            var culturetype    = collection[3];
            var name           = collection[4];
            var firstOrDefault = _growingFruitComingsRepository.Get().FirstOrDefault(c => c.CultureType == culturetype && c.Name == name);

            if (firstOrDefault != null)
            {
                var profit = new GrowingFruitProfits
                {
                    Id             = firstOrDefault.Id,
                    CultureType    = collection[3],
                    Name           = collection[4],
                    ExpirationDate = GetExpirationDateForTern(DateTime.Parse(collection[2]), collection[3]),
                    Remind         = false,
                    User           = _usersRepository.Get().FirstOrDefault(i => i.Id == userId),
                    GrowingType    = _growingTypeRepository.Get().FirstOrDefault(i => i.Name == "Tern")
                };
                await _growingFruitProfitsRepository.AddAsync(profit);
            }
        }
        public async Task AddNewTern(int userId, FormCollection collection)
        {
            var tern = new GrowingFruitComings()
            {
                User = _usersRepository.Get().FirstOrDefault(i => i.Id == userId),
                GrowingType = _growingTypeRepository.Get().FirstOrDefault(i => i.Name == "Tern"),
                LandingDate = DateTime.Parse(collection[1]),
                FloweringDate = DateTime.Parse(collection[2]),
                CultureType = collection[3],
                Name = collection[4],
                MassType = collection[5],
                CurrencyType = collection[6],
                Cost = Convert.ToDecimal(collection[7].Replace(".", ",")),
                Amount = Convert.ToDecimal(collection[8].Replace(".", ",")),
                Document = FileNameValidator(collection[9])
            };

            _growingFruitComingsRepository.Add(tern);
            var culturetype = collection[3];
            var name = collection[4];
            var firstOrDefault = _growingFruitComingsRepository.Get().FirstOrDefault(c => c.CultureType == culturetype && c.Name == name);
            if (firstOrDefault != null)
            {
                var profit = new GrowingFruitProfits
                {
                    Id = firstOrDefault.Id,
                    CultureType = collection[3],
                    Name = collection[4],
                    ExpirationDate = GetExpirationDateForTern(DateTime.Parse(collection[2]), collection[3]),
                    Remind = false,
                    User = _usersRepository.Get().FirstOrDefault(i => i.Id == userId),
                    GrowingType = _growingTypeRepository.Get().FirstOrDefault(i => i.Name == "Tern")
                };
                await _growingFruitProfitsRepository.AddAsync(profit);
            }
        }