Exemple #1
0
        //-> New
        public async Task <DriverViewDTO> New(DriverNewDTO newDTO)
        {
            newDTO = StringHelper.TrimStringProperties(newDTO);
            var record = (tblDriver)MappingHelper.MapDTOToDBClass <DriverNewDTO, tblDriver>(newDTO, new tblDriver());

            record.createdDate = DateTime.Now;
            db.tblDrivers.Add(record);

            await db.SaveChangesAsync();

            db.Entry(record).Reload();
            return(await SelectByID(record.id));
        }
Exemple #2
0
 public async Task <JsonResult> New(DriverNewDTO newDTO)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.KEY_IN_REQUIRED_FIELD);
         }
         Response.StatusCode = 200;
         return(Json(await handler.New(newDTO), JsonRequestBehavior.AllowGet));
     }
     catch (HttpException ex)
     {
         return(Json(ConstantHelper.ERROR, JsonRequestBehavior.AllowGet));
     }
 }