public async Task AddNewSilage(int userId, FormCollection collection) { var groving = new GrowingFieldComings { User = _usersRepository.Get().FirstOrDefault(i => i.Id == userId), GrowingType = _growingTypeRepository.Get().FirstOrDefault(i => i.Name == "Silage"), LandingDate = DateTime.Parse(collection[1]), CultureType = collection[2], Name = collection[3], MassType = collection[4], CurrencyType = collection[5], Cost = Convert.ToDecimal(collection[6].Replace(".", ",")), Amount = Convert.ToDecimal(collection[7].Replace(".", ",")), Document = FileNameValidator(collection[8]) }; _growingFieldComingsRepository.Add(groving); var culturetype = collection[2]; var name = collection[3]; var firstOrDefault = _growingFieldComingsRepository.Get().FirstOrDefault(c => c.CultureType == culturetype && c.Name == name); if (firstOrDefault != null) { var profit = new GrowingFieldProfits { Id = firstOrDefault.Id, CultureType = collection[2], Name = collection[3], ExpirationDate = GetExpirationDateForSilageCulture(DateTime.Parse(collection[1]), collection[2]), Remind = false, User = _usersRepository.Get().FirstOrDefault(i => i.Id == userId), GrowingType = _growingTypeRepository.Get().FirstOrDefault(i => i.Name == "Silage") }; await _growingFieldProfitsRepository.AddAsync(profit); } }
public async Task AddNewMelon(int userId, FormCollection collection) { var groving = new GrowingFieldComings { User = _usersRepository.Get().FirstOrDefault(i => i.Id == userId), GrowingType = _growingTypeRepository.Get().FirstOrDefault(i => i.Name == "Melon"), LandingDate = DateTime.Parse(collection[1]), CultureType = collection[2], Name = collection[3], MassType = collection[4], CurrencyType = collection[5], Cost = Convert.ToDecimal(collection[6].Replace(".", ",")), Amount = Convert.ToDecimal(collection[7].Replace(".", ",")), Document = FileNameValidator(collection[8]) }; _growingFieldComingsRepository.Add(groving); var culturetype = collection[2]; var name = collection[3]; var firstOrDefault = _growingFieldComingsRepository.Get().FirstOrDefault(c => c.CultureType == culturetype && c.Name == name); if (firstOrDefault != null) { var profit = new GrowingFieldProfits { Id = firstOrDefault.Id, CultureType = collection[2], Name = collection[3], ExpirationDate = GetExpirationDateForMelonCulture(DateTime.Parse(collection[1]), collection[2]), Remind = false, User = _usersRepository.Get().FirstOrDefault(i => i.Id == userId), GrowingType = _growingTypeRepository.Get().FirstOrDefault(i => i.Name == "Melon") }; await _growingFieldProfitsRepository.AddAsync(profit); } }