コード例 #1
0
 public ActionResult Create(int id, CreatePlotInput input)
 {
     if (ModelState.IsValid)
     {
         _plotAppService.CreatePlot(input);
         return(RedirectToAction("Index", new { Id = id }));
     }
     else
     {
         var compartment = _compartmentAppService.GetCompartment(id);
         ViewBag.Compartment = compartment;
         return(View(input));
     }
 }
コード例 #2
0
ファイル: PlotAppService.cs プロジェクト: jkisanga/misitu
        public int CreatePlot(CreatePlotInput input)
        {
            var plot = new Plot
            {
                Name          = input.Name,
                CompartmentId = input.CompartmentId
            };


            if (_plotRepository.FirstOrDefault(p => p.Name == input.Name && p.CompartmentId == input.CompartmentId) == null)
            {
                // _plotRepository.InsertAndGetId(plot);

                return(_plotRepository.InsertAndGetId(plot));
            }
            else
            {
                throw new UserFriendlyException("There is already a Plot with given name");
            }
        }
コード例 #3
0
        public ActionResult Talling(int CompartmentId, int SpecieCategoryId, int TariffNumber, HttpPostedFileBase file)
        {
            try
            {
                if (file != null && file.ContentLength > 0)
                {
                    //ExcelDataReader works on binary excel file
                    Stream stream = file.InputStream;

                    var reader = string.Equals(Path.GetExtension(file.FileName), ".xls") ? ExcelReaderFactory.CreateBinaryReader(stream)
                        : ExcelReaderFactory.CreateOpenXmlReader(stream);


                    int plotId;

                    //Loop through data sheet
                    do
                    {
                        while (reader.Read())
                        {
                            CreatePlotInput       input      = new CreatePlotInput();
                            CreateTallySheetInput tallyInput = new CreateTallySheetInput();


                            input.CompartmentId = CompartmentId;
                            input.Name          = reader.Name;

                            string name = reader.Name;

                            plotId = _plotAppService.CreatePlot(input);

                            tallyInput.PlotId           = plotId;
                            tallyInput.SpecieCategoryId = SpecieCategoryId;
                            tallyInput.TariffNumber     = TariffNumber;


                            //treats the first row of excel file as Coluymn Names
                            reader.IsFirstRowAsColumnNames = true;
                            //Adding reader data to DataSet()
                            DataSet result1 = reader.AsDataSet();

                            //Sending result data to database

                            _tallySheetAppService.UploadTallySheet(tallyInput, result1.Tables[reader.Name]);
                            reader.Close();
                        }
                    } while (reader.NextResult());



                    return(RedirectToAction("Index"));
                }

                else
                {
                    ModelState.AddModelError("File", "Please upload your file");
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }