コード例 #1
0
 public int UpdateCab(int id, cabdto cabdetails)
 {
     try
     {
         if (!_context.Cab.Any(r => r.VehicleNo == cabdetails.VehicleNo && r.IsDeleted == false))
         {
             var result = (from c in _context.Cab
                           where c.Id == id
                           select c).SingleOrDefault();
             result.Model     = cabdetails.Model;
             result.VehicleNo = cabdetails.VehicleNo;
             result.Capacity  = Int32.Parse(cabdetails.Capacity);
             _context.SaveChanges();
             return(1);
         }
         else
         {
             throw new Exception();
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
コード例 #2
0
        public int AddCab(cabdto cabdetails)
        {
            try
            {
                if (!_context.Cab.Any(r => r.VehicleNo == cabdetails.VehicleNo && r.IsDeleted == false))
                {
                    var CabDetail = new Cab
                    {
                        Capacity  = Int32.Parse(cabdetails.Capacity),
                        Model     = cabdetails.Model,
                        VehicleNo = cabdetails.VehicleNo
                    };
                    _context.Cab.Add(CabDetail);
                    _context.SaveChanges();
                }
                else
                {
                    throw new Exception();
                }

                return(1);
            }
            catch (Exception e)
            {
                throw  e;
            }
        }
コード例 #3
0
 public IActionResult Edit(int id, [FromBody] cabdto cabdetails)
 {
     try
     {
         return(Ok(cabService.UpdateCab(id, cabdetails)));
     }
     catch (Exception e)
     {
         return(Ok(e));
     }
 }
コード例 #4
0
 public IActionResult Create([FromBody] cabdto cabdetails)
 {
     try
     {
         return(Ok(cabService.AddCab(cabdetails)));
     }
     catch (Exception e)
     {
         return(Ok(e));
     }
 }
コード例 #5
0
 public cabdto GetCabById(int id)
 {
     try
     {
         var result = (from c in _context.Cab
                       where c.Id == id
                       select c).SingleOrDefault();
         cabdto cab = new cabdto {
             Model     = result.Model,
             VehicleNo = result.VehicleNo,
             Capacity  = result.Capacity.ToString()
         };
         return(cab);
     }
     catch (Exception e)
     {
         throw e;
     }
 }