Exemple #1
0
        public async Task <IHttpActionResult> GetS2SCapacity([FromUri] S2SCapacitySlotArgs args)
        {
            if (args.ImportLevel.EqualsIgnoreCase("list"))
            {
                args.Source = "Seeds";
            }
            else
            {
                args.Source = "Plants";
            }
            var resp = await _s2SService.GetS2SCapacityAsync(args);

            return(Ok(resp));
        }
Exemple #2
0
        public async Task <IEnumerable <S2SCapacitySlotResult> > GetS2SCapacityAsync(S2SCapacitySlotArgs args)
        {
            var(UserName, Password) = Credentials.GetCredentials();
            using (var svc = new S2SSoapClient
            {
                Url = ConfigurationManager.AppSettings["S2SCapacitySlotUrl"],
                //Credentials = new NetworkCredential("prakash_as", "20prak!!@@19")
                Credentials = new NetworkCredential(UserName, Password)
            })
            {
                svc.Model = new
                {
                    args.BreEzysAdministration,
                    args.CapacitySlotID,
                    args.Crop,
                    args.Source,
                    args.Year
                };
                var response = await svc.GetS2SCapacityAsync();

                return(response);
            }
        }
Exemple #3
0
        public async Task UploadS2SDonorAsync(int testID)
        {
            //prepare data to upload
            var data = await DbContext.ExecuteReaderAsync(DataConstants.PR_S2S_GET_DONOR_INFO_FOR_UPLOAD,
                                                          CommandType.StoredProcedure, args => args.Add("@TestID", testID), reader => new S2SCreateSowingListData
            {
                CropCode                       = reader.Get <string>(0),
                CapacitySlotID                 = reader.Get <int>(1),
                CapacitySlotName               = reader.Get <string>(2),
                MasterNumber                   = reader.Get <string>(3),
                BreezysPKReference             = reader.Get <string>(4),
                BreezysID                      = reader.Get <int>(5),
                BreezysRefCode                 = reader.Get <int>(6),
                BreedingStation                = reader.Get <string>(7),
                Project                        = reader.Get <string>(8),
                DonorNumber                    = reader.Get <string>(9),
                PlantNumber                    = reader.Get <string>(10),
                LotNumber                      = reader.Get <int>(11),
                CrossingYear                   = 0,
                NrOfSeeds                      = reader.Get <int>(12),
                NrOfPlannedTransplanted        = reader.Get <int>(13),
                NrOfPlannedDHEmbryoRescueNett  = reader.Get <int>(14),
                NrOfPlannedDHEmbryoRescueGross = reader.Get <int>(15),
                DH0MakerTestNeeded             = reader.Get <bool>(16),
                BreEzysAdminstration           = "PH"
            });

            if (!data.Any())
            {
                throw new BusinessException("No donors selected for uploading to S2S.");
            }

            var param = new S2SCapacitySlotArgs()
            {
                BreEzysAdministration = "PH",
                CapacitySlotID        = data.FirstOrDefault().CapacitySlotID,
                Crop = data.FirstOrDefault().CropCode
            };

            //validate sowinglist with the server
            //get capacityslot data
            var getS2SCapacity = await GetS2SCapacityAsync(param);

            if (!getS2SCapacity.Any())
            {
                throw new BusinessException("Could not fetch capacity slot information from Cordys.");
            }
            var s2sCapacity = getS2SCapacity.FirstOrDefault();

            //check if project code is filled or not
            if (data.Any(x => string.IsNullOrWhiteSpace(x.Project)))
            {
                throw new BusinessException("Project Code can not be blank or empty.");
            }

            //check if project code is filled or not
            if (data.Any(x => string.IsNullOrWhiteSpace(x.MasterNumber)))
            {
                throw new BusinessException("MasterNr can not be blank or empty.");
            }

            //update to database
            var TVPS2SCapacity = new DataTable();

            TVPS2SCapacity.Columns.Add("CapacitySlotID", typeof(int));
            TVPS2SCapacity.Columns.Add("CapacitySlotName", typeof(string));
            TVPS2SCapacity.Columns.Add("MaxPlants", typeof(int));
            TVPS2SCapacity.Columns.Add("CordysStatus", typeof(string));
            TVPS2SCapacity.Columns.Add("DH0Location", typeof(string));
            TVPS2SCapacity.Columns.Add("AvailPlants", typeof(int));

            var dr1 = TVPS2SCapacity.NewRow();

            dr1["CapacitySlotID"]   = s2sCapacity.CapacitySlotID;
            dr1["CapacitySlotName"] = s2sCapacity.SowingCode;
            dr1["MaxPlants"]        = s2sCapacity.MaxPlants;
            dr1["CordysStatus"]     = s2sCapacity.Status;
            dr1["DH0Location"]      = s2sCapacity.DH0Location;
            dr1["AvailPlants"]      = s2sCapacity.AvailableNrPlants;
            TVPS2SCapacity.Rows.Add(dr1);

            await DbContext.ExecuteNonQueryAsync(DataConstants.PR_S2S_CREATE_CAPACITYSLOT, CommandType.StoredProcedure, args =>
            {
                args.Add("@TVPCapacityS2S", TVPS2SCapacity);
            });

            //if NrOfPlannedTransplanted is zero send warning message
            if (data.Any(x => x.NrOfPlannedTransplanted <= 0))
            {
                throw new BusinessException("Transplant value cannot be 0 for selected donor.");
            }
            var totalTransplanted = data.Sum(x => x.NrOfPlannedTransplanted);

            //if nr of avail capacity + material to upload is within range then upload else error
            if (s2sCapacity.AvailableNrPlants < totalTransplanted)
            {
                throw new BusinessException("Available capacity exceeded. Unselect some donor.");
            }
            //upload donors
            var donorResult = await UploadDonorlistAsync(data);

            if (donorResult.Any())
            {
                //update donornumber for all donors and update Test status
                var TVPDonorInfo = new DataTable();
                TVPDonorInfo.Columns.Add("MaterialID", typeof(int));
                TVPDonorInfo.Columns.Add("DH0net");
                TVPDonorInfo.Columns.Add("Requested");
                TVPDonorInfo.Columns.Add("ToBeSown");
                TVPDonorInfo.Columns.Add("Transplant");
                TVPDonorInfo.Columns.Add("DonorNumber");
                TVPDonorInfo.Columns.Add("ProjectCode");
                foreach (var item in donorResult)
                {
                    var dr = TVPDonorInfo.NewRow();
                    dr["MaterialID"]  = item.BreezysPKReference;
                    dr["DonorNumber"] = item.DonorNumber;
                    TVPDonorInfo.Rows.Add(dr);
                }
                var donor = await DbContext.ExecuteNonQueryAsync(DataConstants.PR_S2S_UPDATE_DONORNUMBER, CommandType.StoredProcedure, args => { args.Add("@TVP_DonerInfo", TVPDonorInfo); args.Add("@TestID", testID); });

                //again update s2s capcity slot property with changed available after success
                dr1["AvailPlants"] = s2sCapacity.AvailableNrPlants - totalTransplanted < 0 ? 0 : s2sCapacity.AvailableNrPlants - totalTransplanted;
                await DbContext.ExecuteNonQueryAsync(DataConstants.PR_S2S_CREATE_CAPACITYSLOT, CommandType.StoredProcedure, args =>
                {
                    args.Add("@TVPCapacityS2S", TVPS2SCapacity);
                });
            }
        }
Exemple #4
0
        public async Task <IHttpActionResult> GetProjects([FromUri] S2SCapacitySlotArgs args)
        {
            var ds = await _s2SService.GetProjectsAsync(args.Crop);

            return(Ok(ds));
        }