public BaseResponse <bool> Create(YachtTourInformationCreateModel model) { using (var transaction = _db.Database.BeginTransaction()) { try { if (model == null) { return(BaseResponse <bool> .BadRequest(false)); } var rs = _commonValueService.GetListCommonValueByGroup(CommonValueGroupConstant.TourInfoType); DateTime?activetdDate = null; if (model.ActivatedDate.HasValue) { activetdDate = model.ActivatedDate.Value.Date; } var date = DateTime.Now.Date; var info = new YachtTourInformations(); info.InjectFrom(model); info.TourInformationTypeResKey = rs.IsSuccessStatusCode ? rs.ResponseData.FirstOrDefault(x => x.ValueInt == model.TourInformationTypeFid).ResourceKey : null; info.DefaultTitle = model.Title; info.UniqueId = UniqueIDHelper.GenarateRandomString(12); info.LastModifiedBy = _userId; info.LastModifiedDate = date; info.IsActivated = true; info.ActivatedBy = _userId; info.Deleted = false; _db.YachtTourInformations.Add(info); _db.SaveChanges(); var detail = new YachtTourInformationDetails(); detail.InjectFrom(model); detail.InformationFid = info.Id; detail.UniqueId = UniqueIDHelper.GenarateRandomString(12); detail.ActivatedBy = _userId; detail.LastModifiedBy = _userId; detail.LastModifiedDate = date; detail.IsActivated = true; detail.Deleted = false; _db.YachtTourInformationDetails.Add(detail); _db.SaveChanges(); transaction.Commit(); return(BaseResponse <bool> .Success(true)); } catch (Exception ex) { transaction.Rollback(); return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } } }
public BaseResponse <bool> CreateDetail(YachtTourInformationUpdateDetailModel model) { try { DateTime?activetdDate = null; if (model.ActivatedDate.HasValue) { activetdDate = model.ActivatedDate.Value.Date; } if (model == null) { return(BaseResponse <bool> .BadRequest(false)); } var entity = new YachtTourInformationDetails(); entity.InjectFrom(model); entity.InformationFid = model.InformationFid; entity.UniqueId = UniqueIDHelper.GenarateRandomString(12); entity.ActivatedBy = _userId; entity.LastModifiedBy = _userId; entity.LastModifiedDate = DateTime.Now; entity.ActivatedDate = activetdDate; entity.IsActivated = true; entity.Deleted = false; _db.YachtTourInformationDetails.Add(entity); _db.SaveChangesAsync(); return(BaseResponse <bool> .Success(true)); } catch (Exception ex) { return(BaseResponse <bool> .InternalServerError(message : ex.Message, fullMsg : ex.StackTrace)); } }