Example #1
0
 private Threads ReturnProducts(List <Product> list)
 {
     try
     {
         var wrap   = new ThreadWrapper();
         var result = new Threads();
         List <EndProduct> endProducts = new List <EndProduct>();
         foreach (var item in list)
         {
             var newList    = new List <string>();
             var endProduct = new EndProduct();
             endProduct.Title = item.Title;
             foreach (var comment in item.Comments)
             {
                 newList.Add(comment.Comment);
             }
             endProduct.Comments = newList;
             endProducts.Add(endProduct);
             var results = new List <EndProduct>();
             foreach (var product in endProducts)
             {
                 results.Add(product);
             }
             wrap.Threads = results;
         }
         result.ThreadWrapper = wrap;
         return(result);
     }
     catch (Exception)
     {
         _logger.LogCritical("Failed To Return Product From Reddit");
         throw;
     }
 }
Example #2
0
        public async Task <List <ThreadWrapper> > GetAllThreads()
        {
            try
            {
                _logger.LogInformation("Returning All Threads Lists");
                var bsonList = await _threadRepo.GetAllThreads();

                var jsonList   = new List <Threads>();
                var jsonThList = new List <ThreadWrapper>();

                if (bsonList.Count == 0)
                {
                    var list = new List <ThreadWrapper>();
                    list.Add(await AddThreads());
                    return(list);
                }

                for (int i = 0; i < bsonList.Count; i++)
                {
                    if (await ThreadExists(bsonList[i].Id))
                    {
                        TimeSpan ts = DateTime.Now.ToLocalTime() - bsonList[i].UpdatedOn.ToLocalTime();
                        if (ts.TotalMinutes < 5 || bsonList != null)
                        {
                            var json   = new Threads();
                            var th     = new ThreadWrapper();
                            var epList = new List <EndProduct>();
                            for (int j = 0; j < 5; j++)
                            {
                                var ep = new EndProduct();
                                ep.Title    = bsonList[i].ThreadsInBson[j].Title;
                                ep.Comments = bsonList[i].ThreadsInBson[j].Comments;
                                epList.Add(ep);
                            }
                            jsonThList.Add(th);
                            th.Threads         = epList;
                            json.ThreadWrapper = th;
                            jsonList.Add(json);
                        }
                        else
                        {
                            _logger.LogInformation("Updating Threads List");
                            var list = new List <ThreadWrapper>();
                            list.Add(await AddThreads());
                            return(list);
                        }
                    }
                }
                return(jsonThList);
            }
            catch (Exception e)
            {
                _logger.LogCritical("Failed To Get All Thread Lists And Update If Needed. {e}", e);
                throw;
            }
        }
Example #3
0
        public async Task <Threads> GetThreads(string id)
        {
            try
            {
                _logger.LogInformation("Returning Threads List by ID: {id}", id);
                var bson = await _threadRepo.GetThreads(id);

                var json    = new Threads();
                var threadW = new ThreadWrapper();
                var list    = new List <EndProduct>();
                if (bson != null)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        var prod = new EndProduct();
                        prod.Title    = bson.ThreadsInBson[i].Title;
                        prod.Comments = bson.ThreadsInBson[i].Comments;
                        list.Add(prod);
                    }
                    threadW.Threads    = list;
                    json.ThreadWrapper = threadW;
                    json.UpdatedOn     = bson.UpdatedOn;
                    return(json);
                }
                else
                {
                    _logger.LogWarning("Object Not Found In Database");
                    return(null);
                }
            }
            catch (Exception e)
            {
                _logger.LogCritical("Failed To Aquire Response List From Database. {e}", e);
                throw;
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            EndProduct ep       = null;
            var        isExists = new EndProductDAL().Exists(txtCode.Text, EPId);

            if (isExists == true)
            {
                Page.RegisterClientScriptBlock("endproduct", "<script language='javascript'>alert('已经有相同的产品!');</script>");
                return;
            }
            if (string.Equals(ViewType, "edit", StringComparison.OrdinalIgnoreCase))
            {
                EndProductDAL dal = new EndProductDAL();
                ep            = dal.GetEndProductById(EPId);
                ep.Code       = txtCode.Text;
                ep.Name       = txtName.Text;
                ep.Catelog    = Utility.GetSelectedText(ddlCatelog);
                ep.SubCatelog = Utility.GetSelectedText(ddlSubCatelog);
                if (!string.IsNullOrEmpty(txtLong.Text))
                {
                    ep.Long = int.Parse(txtLong.Text);
                }
                if (!string.IsNullOrEmpty(txtWidth.Text))
                {
                    ep.Width = int.Parse(txtWidth.Text);
                }
                if (!string.IsNullOrEmpty(txtDeep.Text))
                {
                    ep.Deepth = int.Parse(txtDeep.Text);
                }
                ep.Material = txtMaterial.Text;
                if (!string.IsNullOrEmpty(txtPrice.Text))
                {
                    ep.Price = double.Parse(txtPrice.Text);
                }
                if (!string.IsNullOrEmpty(txtPriceIn.Text))
                {
                    ep.PurchasePrice = double.Parse(txtPriceIn.Text);
                }
                if (!string.IsNullOrEmpty(txtQty.Text))
                {
                    ep.Qty = int.Parse(txtQty.Text);
                }
                ep.SupplierName = Utility.GetSelectedText(ddlSupplier);
                ep.Location     = Utility.GetSelectedText(ddlLocation);
                ep.Remark       = txtRemark.Text;
                if (!string.IsNullOrEmpty(filePic.FileName))
                {
                    string serverFilePath = string.Empty;
                    Utility.UploadFile(filePic, "EndProductImage", SourceNo, ref serverFilePath);
                    ep.ImgPth = serverFilePath;
                }
                dal.Save();
            }
            else if (string.Equals(ViewType, "create", StringComparison.OrdinalIgnoreCase))
            {
                EndProductDAL dal = new EndProductDAL();
                ep            = new EndProduct();
                ep.Code       = txtCode.Text;
                ep.Name       = txtName.Text;
                ep.Catelog    = Utility.GetSelectedText(ddlCatelog);
                ep.SubCatelog = Utility.GetSelectedText(ddlSubCatelog);
                if (!string.IsNullOrEmpty(txtLong.Text))
                {
                    ep.Long = int.Parse(txtLong.Text);
                }
                if (!string.IsNullOrEmpty(txtWidth.Text))
                {
                    ep.Width = int.Parse(txtWidth.Text);
                }
                if (!string.IsNullOrEmpty(txtDeep.Text))
                {
                    ep.Deepth = int.Parse(txtDeep.Text);
                }
                ep.Material = txtMaterial.Text;
                if (!string.IsNullOrEmpty(txtPrice.Text))
                {
                    ep.Price = double.Parse(txtPrice.Text);
                }
                if (!string.IsNullOrEmpty(txtPriceIn.Text))
                {
                    ep.PurchasePrice = double.Parse(txtPriceIn.Text);
                }
                if (!string.IsNullOrEmpty(txtQty.Text))
                {
                    ep.Qty = int.Parse(txtQty.Text);
                }
                ep.SupplierName = Utility.GetSelectedText(ddlSupplier);
                ep.Location     = Utility.GetSelectedText(ddlLocation);
                ep.Remark       = txtRemark.Text;
                if (!string.IsNullOrEmpty(filePic.FileName))
                {
                    string serverFilePath = string.Empty;
                    Utility.UploadFile(filePic, "EndProductImage", SourceNo, ref serverFilePath);
                    ep.ImgPth = serverFilePath;
                }
                dal.AddEndProduct(ep);
                dal.Save();
            }
            //redirect
            if (string.IsNullOrEmpty(CloseAfter))
            {
                Response.Redirect(string.Format("productform.aspx?type=ep&id={0}&viewtype=edit", ep.EP_Id));
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(typeof(FinishProductEditControl), "closecreate", "javascript:closeWindow();");
            }
        }
Example #5
0
 public void AddEndProduct(EndProduct ep)
 {
     Db.EndProduct.AddObject(ep);
 }