Пример #1
0
        public async Task <IHttpActionResult> PutPensionService(int id, PensionService pensionService)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pensionService.PensionServiceNo)
            {
                return(BadRequest());
            }

            db.Entry(pensionService).State = EntityState.Modified;

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
0
        public async Task <IHttpActionResult> GetPensionService(int id)
        {
            PensionService pensionService = await db.PensionServices.FindAsync(id);

            if (pensionService == null)
            {
                return(NotFound());
            }

            return(Ok(pensionService));
        }
Пример #3
0
        public async Task <IHttpActionResult> PostPensionService(PensionService pensionService)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PensionServices.Add(pensionService);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = pensionService.PensionServiceNo }, pensionService));
        }
Пример #4
0
        public async Task <IHttpActionResult> DeletePensionService(int id)
        {
            PensionService pensionService = await db.PensionServices.FindAsync(id);

            if (pensionService == null)
            {
                return(NotFound());
            }

            db.PensionServices.Remove(pensionService);
            await db.SaveChangesAsync();

            return(Ok(pensionService));
        }
Пример #5
0
        private async Task <List <PensionService> > AddPensionService(Pension pension, string service)
        {
            List <PensionService> pensionServices = new List <PensionService>();
            var arr = HttpUtility.UrlDecode(service.ToString()).Split(',');

            for (int i = 0; i < arr.Length; i++)
            {
                PensionService pensionService = new PensionService();
                pensionService.PensionNo          = pension.PensionNo;
                pensionService.PensionServiceCode = int.Parse(arr[i].ToString());
                pensionServices.Add(pensionService);
            }

            db.PensionServices.AddRange(pensionServices);
            await db.SaveChangesAsync();

            return(pensionServices);
        }