Esempio n. 1
0
        public async Task <ActionResult> Create(CreateCompartmentInput input)
        {
            if (ModelState.IsValid)
            {
                await _compartmentAppService.CreateCompartment(input);

                return(RedirectToAction("Index"));
            }
            else
            {
                var ranges = _rangeAppService.GetRanges().Select(c => new SelectListItem {
                    Value = c.Id.ToString(), Text = c.Name
                });
                ViewBag.RangeId = ranges;
                return(View(input));
            }
        }
Esempio n. 2
0
        public async Task CreateCompartment(CreateCompartmentInput input)
        {
            String   sDate     = DateTime.Now.ToString();
            DateTime datevalue = (Convert.ToDateTime(sDate.ToString()));

            String dy          = datevalue.Day.ToString();
            String mn          = datevalue.Month.ToString();
            String currentYear = datevalue.Year.ToString();



            //get current active financial year;
            var current = _financialYearRepository.FirstOrDefault(c => c.IsActive == true);

            if (current != null)
            {
                int CalculatedAge = Convert.ToInt32(currentYear) - Convert.ToInt32(input.PlantedYear);
                var compartment   = new Compartment
                {
                    Name            = input.Name,
                    RangeId         = input.RangeId,
                    FinancialYearId = current.Id,
                    Species         = input.Species,
                    PlantedYear     = input.PlantedYear,
                    Age             = CalculatedAge,
                    Area            = input.Area,
                    EstimatedVolume = input.EstimatedVolume,
                    Season          = input.Season,
                    TariffNumber    = input.TariffNumber
                };

                var existingCompartment = _compartmentRepository.FirstOrDefault(p => p.Name == input.Name);
                if (existingCompartment == null)
                {
                    await _compartmentRepository.InsertAsync(compartment);
                }
                else
                {
                    throw new UserFriendlyException("There is already a Compartment with given name");
                }
            }
            else
            {
                throw new UserFriendlyException("No Active Financial Year");
            }
        }