Пример #1
0
        //-> New
        public async Task <VehicleViewDTO> New(VehicleNewDTO newDTO)
        {
            newDTO = StringHelper.TrimStringProperties(newDTO);
            var record = (tblVehicle)MappingHelper.MapDTOToDBClass <VehicleNewDTO, tblVehicle>(newDTO, new tblVehicle());

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

            await db.SaveChangesAsync();

            db.Entry(record).Reload();
            return(await SelectByID(record.id));
        }
Пример #2
0
        //-> New
        public async Task <UserViewDTO> New(UserNewDTO newDTO)
        {
            newDTO = StringHelper.TrimStringProperties(newDTO);
            var checkRecord = await db.tblUsers.FirstOrDefaultAsync(x => x.deleted == null && x.userName == newDTO.userName);

            if (checkRecord != null)
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, ConstantHelper.LOGIN_NAME_EXIST);
            }

            var record = (tblUser)MappingHelper.MapDTOToDBClass <UserNewDTO, tblUser>(newDTO, new tblUser());

            record.createdDate = DateTime.Now;
            record.password    = CryptingHelper.EncryptString("123");
            db.tblUsers.Add(record);
            await db.SaveChangesAsync();

            db.Entry(record).Reload();
            return(await SelectByID(record.id));
        }