public JsonResult SendNotification(CasualNotificationDto casualNotification)
        {
            if (ModelState.IsValid)
            {
                Image image;
                if (casualNotification.Avatar != null)
                {
                    image = ImageHandler.CreateWebImage(casualNotification.Avatar, casualNotification.Title,
                                                        WebImageType.NOTIFICATION_IMAGE);
                }
                else
                {
                    image = ImageHandler.CreateDefaultImage(casualNotification.Title, WebImageType.NOTIFICATION_IMAGE);
                }

                NotificationGenerator.CasualNotification(db, casualNotification.Title, casualNotification.Message, image);

                return(Json(new
                {
                    result = true
                }));
            }
            return(Json(new
            {
                result = false
            }));
        }
예제 #2
0
        public IHttpActionResult Send(CasualNotificationDto casualNotification)
        {
            if (ModelState.IsValid)
            {
                string imageFilePath     = "";
                var    folderRandomIndex = RandomHelper.RandomInt(0, 10000);
                if (casualNotification.Avatar != null)
                {
                    var fileRandomIndex = RandomHelper.RandomInt(0, 10000);

                    var fileExtension = Path.GetExtension(casualNotification.Avatar.FileName);

                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Image/Notification/" + folderRandomIndex));

                    var fileName = fileRandomIndex + DateTime.Now.ToString("yy-MM-dd-hh-mm-ss") +
                                   fileExtension;
                    imageFilePath = "/Image/Notification/" + folderRandomIndex + "/" + fileName;
                    fileName      =
                        Path.Combine(HttpContext.Current.Server.MapPath("~/Image/Notification/" + folderRandomIndex + "/"), fileName);
                    casualNotification.Avatar.SaveAs(fileName);
                }
                else
                {
                    //Default
                    imageFilePath = "/Image/Games/Default/Default.jpg";
                }

                Image image = new Image()
                {
                    CreatedAt = DateTime.Now,
                    Type      = ImageType.NOTIFICATION_IMAGE,
                    ImagePath = imageFilePath,
                    Name      = casualNotification.Title,
                    UpdatedAt = DateTime.Now
                };

                NotificationGenerator.CasualNotification(db, casualNotification.Title, casualNotification.Message, image);

                return(Ok());
            }
            return(BadRequest());
        }