示例#1
0
        public async Task <IActionResult> UpdateRating(int id, [FromBody] MstRating mstRating)
        {
            try
            {
                if (mstRating != null && id != 0)
                {
                    using (EzyFind_DevContext db = new EzyFind_DevContext())
                    {
                        db.MstRating.Update(mstRating);
                        await db.SaveChangesAsync();

                        id = mstRating.MstRatingId;
                    }

                    response.Status  = true;                         // Operation Status Indicator
                    response.Message = "Successful: Rating updated"; // Exception Message
                    response.Result  = id;
                    return(Ok(response));
                }
                else
                {
                    response.Status  = false;                          // Operation Status Indicator
                    response.Message = "Warning : No Rating provided"; // Exception Message
                    response.Result  = null;
                    return(Ok(response));
                }
            }
            catch
            {
                response.Status  = false;                             // Operation Status Indicator
                response.Message = "Error : Unable to update Rating"; // Exception Message
                response.Result  = null;
                return(Ok(response));
            }
        }
        public async Task <IActionResult> PutMstRating([FromRoute] int id, [FromBody] MstRating mstRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != mstRating.MstRatingId)
            {
                return(BadRequest());
            }

            _context.Entry(mstRating).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MstRatingExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PostMstRating([FromBody] MstRating mstRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.MstRating.Add(mstRating);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetMstRating", new { id = mstRating.MstRatingId }, mstRating));
        }