예제 #1
0
        // POST: api/PointList/
        public IHttpActionResult PostPointList([FromBody] JObject jObject)
        {
            dynamic   jobject     = jObject;
            var       pointItemId = (int)jobject.pointItemId;
            string    userId      = User.Identity.GetUserId();
            string    userName    = User.Identity.GetUserName();
            PointItem result      = context.PointItems.SingleOrDefault(c => c.Id == pointItemId);
            var       value       = new PointList
            {
                UserId        = userId,
                UserName      = userName,
                PointItemId   = result.Id,
                PointItemName = result.Name,
                Points        = result.Points,
                Remark        = "",
                DateAdded     = DateTime.Now
            };

            context.PointLists.Add(value);
            context.SaveChanges();

            //管理者情報の取得
            var mailContext = context.Users
                              .Join(context.UserRoles, a => a.Id, b => b.UserId, (a, b) => new { a.UserName, a.Email, b.RoleId })
                              .Join(context.Roles, ab => ab.RoleId, d => d.Id, (ab, c) => new { ab.UserName, ab.Email, c.Name })
                              .Where(d => d.Name == "CanManagePointItem")
                              .FirstOrDefault();

            //SendGridのメール配信呼び出し
            SendEmail sendEmail  = new SendEmail();
            var       mailResult = sendEmail.CallSendGridApi(userName, mailContext.UserName, mailContext.Email);

            return(Ok());
        }