Пример #1
0
        public bool Update(YachtTourCategoryCreateModel model)
        {
            try
            {
                if (model == null)
                {
                    return(false);
                }

                var entity = _dbYachtContext.YachtTourCategoryInfomations.FirstOrDefault(e => e.Deleted == false && e.Id == model.Id);
                entity = _mapper.Map <YachtTourCategoryCreateModel, YachtTourCategoryInfomations>(model, entity);
                entity.LastModifiedBy   = GetCurrentUserId();
                entity.LastModifiedDate = DateTime.UtcNow;
                if (model.ActivatedDate.HasValue)
                {
                    model.ActivatedDate = model.ActivatedDate.Value.Date;
                }
                if (model.FileStreamFid > 0)
                {
                    entity.FileStreamFid = model.FileStreamFid;
                }
                if (model.FileTypeFid > 0)
                {
                    entity.FileTypeFid = model.FileTypeFid;
                }

                _dbYachtContext.SaveChanges();
                return(true);
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        public bool Create(YachtTourCategoryCreateModel model)
        {
            using (var transaction = _dbYachtContext.Database.BeginTransaction())
            {
                try
                {
                    var _userId = _workContext.UserGuid;
                    var _date   = DateTime.Now;

                    if (model == null)
                    {
                        return(false);
                    }

                    DateTime?activetdDate = null;
                    if (model.ActivatedDate.HasValue)
                    {
                        activetdDate = model.ActivatedDate.Value.Date;
                    }

                    var info = new YachtTourCategories();
                    info                  = _mapper.Map <YachtTourCategoryCreateModel, YachtTourCategories>(model, info);
                    info.IsActivated      = true;
                    info.Deleted          = false;
                    info.LastModifiedBy   = _userId;
                    info.LastModifiedDate = _date;
                    info.CreatedBy        = _userId;
                    info.CreatedDate      = _date;
                    _dbYachtContext.YachtTourCategories.Add(info);
                    _dbYachtContext.SaveChanges();

                    var detail = new YachtTourCategoryInfomations();
                    detail = _mapper.Map <YachtTourCategoryCreateModel, YachtTourCategoryInfomations>(model, detail);
                    detail.TourCategoryFid  = info.Id;
                    detail.Deleted          = false;
                    detail.LastModifiedBy   = _userId;
                    detail.LastModifiedDate = _date;
                    detail.CreatedBy        = _userId;
                    detail.CreatedDate      = _date;
                    _dbYachtContext.YachtTourCategoryInfomations.Add(detail);
                    _dbYachtContext.SaveChanges();

                    transaction.Commit();
                    return(true);
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
 public IActionResult Create([FromBody] YachtTourCategoryCreateModel createModel)
 {
     try
     {
         var result = _yachtTourCategoryService.Create(createModel);
         if (result)
         {
             return(Ok(result));
         }
         return(BadRequest());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.StackTrace.ToString()));
     }
 }
Пример #4
0
        public YachtTourCategoryCreateModel FindInfoDetailById(long id)
        {
            try
            {
                var tourCate = new YachtTourCategoryCreateModel();
                var entity   = _dbYachtContext.YachtTourCategoryInfomations.AsNoTracking()
                               .FirstOrDefault(e => e.Deleted == false && e.Id == id);
                if (entity == null)
                {
                    return(tourCate);
                }
                var model = new YachtTourCategoryCreateModel();

                return(tourCate);
            }
            catch
            {
                throw;
            }
        }