public async System.Threading.Tasks.Task <ActionResult> Edit(Product pd, HttpPostedFileBase image)
        {
            try
            {
                if (string.IsNullOrEmpty(pd.image) && image != null)
                {
                    string filename = "";
                    filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                    Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                    _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                    var imageUrl = await _imageUploader.UploadImage(image, filename, "Mall");

                    pd.image = imageUrl;
                }
                if ((pd.unitSn == 1 || pd.unitSn == 2) && pd.type != 3)
                {
                    pd.Price = pd.Price * 1.2 * 100000 / 30;
                }
                // TODO: Add update logic here
                new MallRepository().Update(pd);
                return(RedirectToAction("Mall"));
            }
            catch
            {
                return(View());
            }
        }
        public async System.Threading.Tasks.Task <string> AddBugCreate(ProblemViewModel pbvm)
        {
            ControllerContext.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            try
            {
                if (string.IsNullOrEmpty(pbvm.image_1) && pbvm.image1 != null)
                {
                    string filename = "";
                    filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                    Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                    _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                    var imageUrl = await _imageUploader.UploadImage(pbvm.image1, filename, "Problem");

                    pbvm.image_1 = imageUrl;
                }

                if (string.IsNullOrEmpty(pbvm.image_2) && pbvm.image2 != null)
                {
                    string filename = "";
                    filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                    Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                    _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                    var imageUrl = await _imageUploader.UploadImage(pbvm.image2, filename, "Problem");

                    pbvm.image_2 = imageUrl;
                }

                if (string.IsNullOrEmpty(pbvm.image_3) && pbvm.image3 != null)
                {
                    string filename = "";
                    filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                    Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                    _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                    var imageUrl = await _imageUploader.UploadImage(pbvm.image3, filename, "Problem");

                    pbvm.image_3 = imageUrl;
                }


                pbvm.valid   = 1;
                pbvm.inpdate = DateTime.Now;

                new UserRepository().addbug(pbvm);
                // TODO: Add insert logic here

                return("1");
            }
            catch
            {
                return("");
            }
            return("");
        }
Пример #3
0
        public override void initialize(string accessKey, string baseLang)
        {
            base.initialize(accessKey, baseLang);
            Google.Apis.Auth.OAuth2.GoogleCredential credential = Google.Apis.Auth.OAuth2.GoogleCredential.FromFile(accessKey);
            credential = credential.CreateScoped(new[] { VisionService.Scope.CloudPlatform });

            visionService = new VisionService(new BaseClientService.Initializer {
                HttpClientInitializer = credential,
                GZipEnabled           = false
            });
        }
Пример #4
0
        public async System.Threading.Tasks.Task <ActionResult> Create(MissionViewModel mvm, HttpPostedFileBase image)
        {
            try
            {
                Mapper.Initialize(cfg => {
                    cfg.CreateMap <MissionViewModel, Missions>();
                });
                Missions             mission           = Mapper.Map <Missions>(mvm);
                List <MissionStart>  MissionStartList  = mvm.MissionStartList;
                List <MissionEnd>    MissionEndList    = mvm.MissionEndList;
                List <MissionAssets> MissionAssetsList = mvm.MissionAssetList;

                if (string.IsNullOrEmpty(mission.imgURL) && image != null)
                {
                    string filename = "";
                    filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                    Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                    _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                    var imageUrl = await _imageUploader.UploadImage(image, filename, "MissionImg");

                    mission.imgURL = imageUrl;
                }


                MissionsRepository mr = new MissionsRepository();
                mission.valid = 1;
                mr.AddMission(mission);
                foreach (var m in MissionStartList)
                {
                    m.missionSn = mission.sn;
                    mr.AddMissionStart(m);
                }
                foreach (var m in MissionEndList)
                {
                    m.missionSn = mission.sn;
                    mr.AddMissionEnd(m);
                }
                foreach (var m in MissionAssetsList)
                {
                    m.missionSn = mission.sn;
                    mr.AddMissionAsset(m);
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                return(View(mvm));
            }
        }
        public async System.Threading.Tasks.Task <ActionResult> _topicCreate(SettingListDto setting, HttpPostedFileBase image, HttpPostedFileBase hoverimage)
        {
            if (setting != null && ModelState.IsValid)
            {
                foreach (var s in setting.topicsettingList)
                {
                    if (string.IsNullOrEmpty(s.image) && image != null)
                    {
                        string filename = "";
                        filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                        Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                        _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                        var imageUrl = await _imageUploader.UploadImage(image, filename, "Topicsimg");

                        s.image = imageUrl;
                    }

                    if (string.IsNullOrEmpty(s.hoverImage) && hoverimage != null)
                    {
                        string filename = "";
                        filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                        Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                        _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                        var imageUrl = await _imageUploader.UploadImage(hoverimage, filename, "Topicsimg");

                        s.hoverImage = imageUrl;
                    }
                }
                ;
                await new DgonHonusRepository().topicSettingCreate(setting);
                //this.teamsRepository.Create(teams);
                return(View(setting));
                //return RedirectToAction("nabobindex", "Setting");
            }
            else
            {
                return(View(setting));
            }
        }
        public async System.Threading.Tasks.Task <ActionResult> Create(Product pt, HttpPostedFileBase image)
        {
            try
            {
                if (string.IsNullOrEmpty(pt.image) && image != null)
                {
                    string filename = "";
                    filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                    Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                    _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                    var imageUrl = await _imageUploader.UploadImage(image, filename, "Mall");

                    pt.image = imageUrl;
                }
                pt.valid = 1;

                if (pt.unitSn == 1 || pt.unitSn == 2)
                {
                    pt.Price = Math.Ceiling((double)pt.Price * 1.2 * 30000 / 30);
                }
                if (pt.createDate == null)
                {
                    pt.createDate = DateTime.Now;
                }

                new MallRepository().MallCreate(pt);
                // TODO: Add insert logic here

                return(RedirectToAction("Mall"));
            }
            catch
            {
                return(View());
            }
        }
        public async System.Threading.Tasks.Task <ActionResult> Create(placard news, HttpPostedFileBase image)
        {
            if (news != null && ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(news.image) && image != null)
                {
                    string filename = "";
                    filename = DateTime.Now.ToString("yyyyMMddTHHmmssfff");
                    Google.Apis.Auth.OAuth2.GoogleCredential credential = await Google.Apis.Auth.OAuth2.GoogleCredential.GetApplicationDefaultAsync();

                    _imageUploader = new ImageUploader(System.Web.Configuration.WebConfigurationManager.AppSettings["GoogleCloud:BucketName"]);
                    var imageUrl = await _imageUploader.UploadImage(image, filename, "News");

                    news.image = imageUrl;
                }

                //Send to all subscribers
                if (news.mail_bear == 1)
                {
                    string timemessenger;



                    var request = WebRequest.Create("https://onesignal.com/api/v1/notifications") as HttpWebRequest;

                    request.KeepAlive   = true;
                    request.Method      = "POST";
                    request.ContentType = "application/json; charset=utf-8";

                    request.Headers.Add("authorization", "Basic YmJkNzJjYmMtNzcwNi00NDhjLWE5N2QtNWQxZWM2YzEwMGI4");
                    var serializer = new JavaScriptSerializer();
                    var obj        = new object();
                    if (news.time != null)
                    {
                        timemessenger  = Convert.ToDateTime(news.time).ToString("yyyy-MM-dd HH:mm:ss");
                        timemessenger += " GMT+0800";
                        obj            = new
                        {
                            app_id            = "d7213a53-69e2-4845-b4d3-b487528a2483",
                            contents          = new { en = news.title },
                            headings          = new { en = "熊i猜-熊報信" },
                            included_segments = new string[] { "All" },
                            ttl              = 2419200,
                            delayed_option   = "last-active",
                            chrome_web_image = news.image,
                            chrome_web_badge = news.image,
                            send_after       = timemessenger
                        };
                    }
                    else
                    {
                        obj = new
                        {
                            app_id            = "d7213a53-69e2-4845-b4d3-b487528a2483",
                            contents          = new { en = news.title },
                            headings          = new { en = "熊i猜-熊報信" },
                            included_segments = new string[] { "All" },
                            ttl              = 2419200,
                            delayed_option   = "last-active",
                            chrome_web_image = news.image,
                            chrome_web_badge = news.image
                        };
                    }
                    var    param     = serializer.Serialize(obj);
                    byte[] byteArray = Encoding.UTF8.GetBytes(param);

                    string responseContent = null;

                    try
                    {
                        using (var writer = request.GetRequestStream())
                        {
                            writer.Write(byteArray, 0, byteArray.Length);
                        }

                        using (var response = request.GetResponse() as HttpWebResponse)
                        {
                            using (var reader = new StreamReader(response.GetResponseStream()))
                            {
                                responseContent = reader.ReadToEnd();
                            }
                        }
                    }
                    catch (WebException ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                        System.Diagnostics.Debug.WriteLine(new StreamReader(ex.Response.GetResponseStream()).ReadToEnd());
                    }

                    System.Diagnostics.Debug.WriteLine(responseContent);
                }
                //Send to all subscribers END



                this.newsRepository.Create(news);
                return(RedirectToAction("News"));
            }
            else
            {
                return(View(news));
            }
        }