Esempio n. 1
0
        public ActionResult ViewPackage(int packageId)
        {
            var package = new PackageDTO();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:54155/api/");
                //HTTP GET
                var responseTask = client.GetAsync($"Package/GetPackage/{packageId}");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <PackageDTO>();
                    readTask.Wait();

                    package = readTask.Result;
                }
            }

            return(View(package));
        }
Esempio n. 2
0
        public async void SendPackage(PackageDTO package)
        {
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    Log.Info("Starting Data transfer");

                    this.GetConnectionSettings();

                    client.BaseAddress = new Uri(this.baseUrl);
                    client.Timeout     = new TimeSpan(0, 0, this.timeoutSec);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Add(WebConfigurationManager.AppSettings["ApiKey"], WebConfigurationManager.AppSettings["ApiKeyValue"]);

                    string        json    = JsonConvert.SerializeObject(package, Newtonsoft.Json.Formatting.Indented);
                    StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

                    HttpResponseMessage response = await client.PostAsync(this.controllerUrn, content);

                    if (response.IsSuccessStatusCode)
                    {
                        Log.Info("Data sucsessfully transfered");
                    }
                    else
                    {
                        Log.Info("Error occured during Data transfer");
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("Exception occured while trying to send SportEvents", ex);
                }
            }
        }
Esempio n. 3
0
        public ActionResult CalculatePrice(int packageId, string additionalServices)
        {
            var package = new PackageDTO();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:54155/api/");
                //HTTP GET
                var services     = !string.IsNullOrEmpty(additionalServices) ? additionalServices : "0";
                var responseTask = client.GetAsync($"Package/CalculatePrice/{packageId}/{services}");
                responseTask.Wait();

                var result = responseTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <PackageDTO>();
                    readTask.Wait();

                    package = readTask.Result;
                }
            }

            ViewBag.cardOptions = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "Credit Card", Value = "1"
                },
                new SelectListItem()
                {
                    Text = "Debit Card", Value = "2"
                }
            };

            return(PartialView("_calculatePrice", package));
        }
Esempio n. 4
0
 private PackageDTO getpackge_update()
 {
     PackageDTO sign = new PackageDTO();
     UserLoginDTO userLogin = getUserLogin();
     if (userLogin != null)
     {
         sign.packageId = Convert.ToInt32(hdfId.Value);
         sign.packageName = txtname.Text;
         sign.description = txtdescription.Text;
         int temp = 0;
         int.TryParse(txtsubaccount.Text, out temp);
         sign.subAccontCount = temp;
         int.TryParse(drlPackageLimit.Text, out temp);
         sign.limitId = int.Parse(drlPackageLimit.SelectedValue);
         if (!ceIsUnlimit.Checked)
         {
             int.TryParse(txtEmailCount.Text, out temp);
             sign.emailCount = temp;
         }
         sign.isUnLimit = ceIsUnlimit.Checked;
         sign.isActive = ceIsActive.Checked;
         sign.isTry = ceTry.Checked;
     }
     return sign;
 }
Esempio n. 5
0
        public List <int> CalculatePackage(ShipmentDTO shippment)
        {
            try
            {
                //TODO: AutoMapper from DTO to entites

                // validate packages base on creteria required
                List <PackageDTO> validPackages = _validatePackage.Validate(shippment.Packages, shippment.MaxWeightAllowed);
                if (!validPackages.Any())
                {
                    return(null);
                }

                List <PackageDTO> validPackagesOrdered = validPackages
                                                         .OrderByDescending(x => x.Price)
                                                         .ThenByDescending(z => z.Weight).ToList();

                List <PackValue> packVal = new List <PackValue>(); // will hold final list of all packages combinations that are fulfill the criteria
                if (validPackagesOrdered.Count > 1)                // if there are more then one packages select them
                {
                    for (int i = 0; i < validPackagesOrdered.Count; i++)
                    {
                        var currentPack = validPackagesOrdered[i];

                        // add this package to the list as single first
                        packVal.Add(new PackValue()
                        {
                            Price   = decimal.Parse(currentPack.Price),
                            Indexes = new List <int>()
                            {
                                currentPack.Index
                            }
                        });

                        // foreach valid packages find other packages to match and increase the value but not more then max weight value
                        var stackPack = new Stack <PackageDTO>(validPackagesOrdered);
                        while (stackPack.Count > 0)
                        {
                            PackageDTO packFromStack = stackPack.Pop();

                            if (currentPack.Index != packFromStack.Index)
                            {
                                if ((currentPack.Weight + packFromStack.Weight) <= shippment.MaxWeightAllowed)
                                {
                                    List <int> newIndexList = new List <int>();
                                    newIndexList.Add(currentPack.Index);
                                    newIndexList.Add(packFromStack.Index);

                                    decimal currentMaxPrice = (decimal.Parse(currentPack.Price) + decimal.Parse(packFromStack.Price));

                                    // if there is unused weight then search packages with weight less then unused and add them to the list (to increase the value)
                                    var unusedWeight = shippment.MaxWeightAllowed - (currentPack.Weight + packFromStack.Weight);
                                    var packagesList = validPackagesOrdered.Where(
                                        x => x.Weight <= unusedWeight &&
                                        x.Index != currentPack.Index &&
                                        x.Index != packFromStack.Index)
                                                       .OrderByDescending(y => y.Price)
                                                       .ThenByDescending(z => z.Weight).ToList();

                                    if (packagesList.Any())
                                    {
                                        newIndexList.Add(packagesList.First().Index);
                                        currentMaxPrice = currentMaxPrice + decimal.Parse(packagesList.First().Price);
                                    }

                                    // add the pack
                                    packVal.Add(new PackValue()
                                    {
                                        Price   = currentMaxPrice,
                                        Indexes = newIndexList
                                    });;
                                }
                            }
                        }
                    }
                }
                else
                {
                    // add the pack
                    packVal.Add(new PackValue()
                    {
                        Price   = decimal.Parse(validPackagesOrdered.First().Price),
                        Indexes = new List <int>()
                        {
                            validPackagesOrdered.First().Index
                        }
                    });;
                }

                // order valid packages by value(price)
                var maxValuePack = packVal.OrderByDescending(x => x.Price);

                // return packages with most combine price
                return(maxValuePack.First().Indexes);
            }
            catch (Exception)
            {
                // TODO: Log error

                return(null);
            }
        }
 public PackageService(PackageDTO packageDto)
 {
     _packageDto = packageDto;
 }
Esempio n. 7
0
 public void tblPackage_insert(PackageDTO dt)
 {
     string sql = "INSERT INTO tblPackage (packageName, description,limitId, emailCount, isUnlimit,subAccontCount,isActive, isTry) " +
                  "VALUES( @packageName, @description,@limitId, @emailCount, @isUnlimit,@subAccontCount,@isActive, @isTry) ";
     SqlCommand cmd = new SqlCommand(sql, ConnectionData._MyConnection);
     cmd.CommandType = CommandType.Text;
     cmd.Parameters.Add("@packageName", SqlDbType.NVarChar).Value = dt.packageName;
     cmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = dt.description;
     cmd.Parameters.Add("@limitId", SqlDbType.Int).Value = dt.limitId;
     cmd.Parameters.Add("@emailcount", SqlDbType.BigInt).Value = dt.emailCount;
     cmd.Parameters.Add("@isUnLimit", SqlDbType.Bit).Value = dt.isUnLimit;
     cmd.Parameters.Add("@subAccontCount", SqlDbType.Int).Value = dt.subAccontCount;
     cmd.Parameters.Add("@isActive", SqlDbType.Bit).Value = dt.isActive;
     cmd.Parameters.Add("@isTry", SqlDbType.Bit).Value = dt.isTry;
     cmd.ExecuteNonQuery();
     cmd.Dispose();
 }
Esempio n. 8
0
    public void tblPackage_Update(PackageDTO dt)
    {
        string sql = "UPDATE tblPackage SET " +
                    "packageName = @packageName, " +
                    "limitId= @limitId, " +
                    "subAccontCount= @subAccontCount, " +
                     "description= @description, " +
                     "isActive= @isActive, " +
                     "emailcount= @emailCount, " +
                     "isTry= @isTry, " +
                     "isunlimit= @isUnlimit " +
                    " WHERE packageId = @packageId";
        SqlCommand cmd = new SqlCommand(sql, ConnectionData._MyConnection);
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.Add("@packageName", SqlDbType.NVarChar).Value = dt.packageName;
        cmd.Parameters.Add("@limitId", SqlDbType.Int).Value = dt.limitId;
        cmd.Parameters.Add("@subAccontCount", SqlDbType.Int).Value = dt.subAccontCount;
        cmd.Parameters.Add("@description", SqlDbType.NVarChar).Value = dt.description;
        cmd.Parameters.Add("@emailcount", SqlDbType.BigInt).Value = dt.emailCount;
        cmd.Parameters.Add("@isUnLimit", SqlDbType.Bit).Value = dt.isUnLimit;
        cmd.Parameters.Add("@isActive", SqlDbType.Bit).Value = dt.isActive;
        cmd.Parameters.Add("@packageId", SqlDbType.Int).Value = dt.packageId;
        cmd.Parameters.Add("@isTry", SqlDbType.Bit).Value = dt.isTry;
        cmd.ExecuteNonQuery();
        cmd.Dispose();
    }
Esempio n. 9
0
 public string DeletePackage(PackageDTO packageDto)
 {
     return("POST ERR - No delete");
 }
Esempio n. 10
0
 public IHttpActionResult PostPackage([FromBody] PackageDTO package)
 {
     this.instance = BalancerMonitor.GetInstance();
     this.instance.SendIncomingEvents(package, Request.RequestUri.GetLeftPart(UriPartial.Authority));
     return(this.Ok());
 }
Esempio n. 11
0
 public string CreatePackage(PackageDTO packageDto)
 {
     return(_packageService.CreatePackage(packageDto));
 }
Esempio n. 12
0
 public void EditPackage(PackageDTO package)
 {
     _realm.Write(() => _realm.Add(package, true));
 }
Esempio n. 13
0
 public void AddPackage(PackageDTO package)
 {
     _realm.Write(() => _realm.Add(package));
 }
Esempio n. 14
0
 public void tblPackage_Update(PackageDTO dt)
 {
     sign.tblPackage_Update(dt);
 }
Esempio n. 15
0
 public void tblPackage_insert(PackageDTO dt)
 {
     sign.tblPackage_insert(dt);
 }