protected override LineDto UpdateImpl(LineDto dto) { var results = from item in SeedData.Ton.Lines where item.Id == dto.Id select item; if (results.Count() == 1) { CheckContraints(dto); var lineToUpdate = results.First(); SeedData.Ton.Lines.Remove(lineToUpdate); dto.Id = Guid.NewGuid(); SeedData.Ton.Lines.Add(dto); UpdateReferences(lineToUpdate, dto); return(dto); } else { if (results.Count() == 0) { throw new Exceptions.IdNotFoundException(dto.Id); } else { throw new Exceptions.VeryBadException(); } } }
//Cập nhật Brand public async Task <bool> Update(LineDto model) { var Line = _mapper.Map <Line>(model); _repoLine.Update(Line); return(await _repoLine.SaveAll()); }
public async Task <LineDto> UpdateLine(LineDto line, string clientId) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (line != null) { if (line.ClientId == clientId) { LineEntity entity = line.ToModel(); entity.LineId = line.LineId; db.Lines.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != "LineId") { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
protected override LineDto InsertImpl(LineDto dto) { var results = from item in SeedData.Ton.Lines where item.Id == dto.Id select item; if (results.Count() == 0) { CheckContraints(dto); dto.Id = Guid.NewGuid(); SeedData.Ton.Lines.Add(dto); //ADD LINE.ID TO USER var resultsUser = from u in SeedData.Ton.Users where u.Id == dto.UserId select u; var user = resultsUser.First(); user.LineIds.Add(dto.Id); return(dto); } else { if (results.Count() == 1) //ID ALREADY EXISTS { throw new Exceptions.IdAlreadyExistsException(dto.Id); } else //MULTIPLE IDS ALREADY EXIST?? { throw new Exceptions.VeryBadException(); } } }
public async Task <LineDto> CreateLine(LineDto lineDto, SelectedNumberDto selectedNumberDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (lineDto == null) { return(null); } else { lineDto.SelectedNumbers = selectedNumberDto; db.Lines.Add(lineDto.ToModel()); await db.SaveChangesAsync(); return(lineDto); } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
private bool CheckIfPackageBelongsToClient(PackageDto package, int lineId, string clientId) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { LineRepository lineRepository = new LineRepository(); LineDto line = lineRepository.GetLine(lineId); if (line != null) { if (line.PackageId == package.PackageId) { if (line.ClientId == clientId) { return(true); } return(false); } return(false); } return(false); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(false); } }
public double GetNumberOfMinutes(LineDto line, PackageIncludesDto packageIncludes) { lock (obj) { return(callManager.GetNumberOfMinutes(line, packageIncludes)); } }
public IActionResult CreateLine([FromBody] LineDto LineDto) { //null Dto if (LineDto == null) { return(BadRequest(ModelState)); } //if state not valid if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // all correct! create the new network ,return it using the mapper!-->create the model var newLine = _mapper.Map <Line>(LineDto); //check if record was created successfully or not if (!_LineRepository.CreateLine(newLine)) { ModelState.AddModelError("", $"Something is wrong with the creation of the record{newLine.Id}"); return(StatusCode(500, ModelState)); } //return the created object instead of a simple ok answer return(CreatedAtRoute("GetLine", new { LineId = newLine.Id }, newLine)); }
public async Task <LineDto> UpdateLine(int id, LineDto lineDto) { using (CellularCompanyContext db = new CellularCompanyContext()) { try { if (lineDto != null && id != 0 && CheckIfLineNumberAlreadyExist(lineDto.Number)) { lineDto.LineId = id; Line entity = lineDto.ToModel(); db.Lines.Attach(entity); foreach (var propName in db.Entry(entity).CurrentValues.PropertyNames) { if (propName != nameof(entity.LineId)) { db.Entry(entity).Property(propName).IsModified = true; } } await db.SaveChangesAsync(); return(entity.ToDto()); } return(null); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } } }
/// <summary> /// 重新插值 /// </summary> /// <param name="dto">线路</param> /// <param name="speed">速度</param> /// <param name="interval">间隔时间</param> /// <param name="alldistance">线路总长度,单位m</param> /// <returns></returns> public static List <LocationDto> Reinterpolation(LineDto dto, double speed, int interval, out double alldistance) { var intervalDistance = speed / 3.6 * interval; alldistance = 0d; var locations = new List <LocationDto> { dto.Locations.First() }; var nextDistance = intervalDistance; var startLocation = locations.Last(); for (int i = 1; i < dto.Locations.Count - 1; i++) { var endLocation = dto.Locations[i]; alldistance += LocationInterpolation.CalculateDistanceBetweenLocations(dto.Locations[i - 1], endLocation); while (true) { var distance = LocationInterpolation.CalculateDistanceBetweenLocations(startLocation, endLocation); if (distance < nextDistance) { nextDistance -= distance; startLocation = endLocation; break; } nextDistance = intervalDistance; startLocation = LocationInterpolation.IntermediaryLocation(startLocation, endLocation, intervalDistance); locations.Add(startLocation); } } return(locations); }
public async Task <IActionResult> Update(LineDto update) { if (await _lineService.Update(update)) { return(NoContent()); } return(BadRequest($"Updating model name {update.ID} failed on save")); }
public double CalculateNumberOfMinutesLeftInPackage(int minutesInPackage, LineDto line) { lock (obj) { List <CallsDto> list = callManager.GetCallsDtos(line.LineId).ToList(); double minutesUsed = list.Sum(l => l.Duration); return(minutesInPackage - minutesUsed); } }
public async Task <IActionResult> Update(LineDto dto) { await lineService.Update(dto); return(Ok(new JsonResultDto <LineDto> { Data = dto })); }
public async Task <IActionResult> Remove(LineDto lineDto) { using (var logger = _loggerManager.CreateLogger()) { await _lineService.RemoveAsync(lineDto); logger.LogInformation($"Line {lineDto.LineName} is deleted successfully."); return(Ok()); } }
public async Task <IActionResult> Add(LineDto dto) { var result = await lineService.Add(dto) > 0; return(Ok(new JsonResultDto <bool> { Data = result, Message = result ? null : "操作失败" })); }
public async Task <LineDto> AddLineEntity(LineDto line, SelectedNumbersDto selectedNumbers) { Task <LineDto> lineDto; lock (obj) { lineDto = lineManager.AddLine(line, selectedNumbers); } return(await lineDto); }
public async Task <LineDto> UpdateLine(int lineId, LineDto line) { Task <LineDto> lineDto; lock (obj) { lineDto = lineManager.UpdateLineDto(line, lineId); } return(await lineDto); }
protected override LineDto InsertImpl(LineDto dto) { using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) { var newLineData = EfHelper.AddToContext(dto, ctx.ObjectContext); ctx.ObjectContext.SaveChanges(); dto.Id = newLineData.Id; return(dto); } }
public async Task <double> GetNumberOfMinutes(LineDto line, PackageIncludesDto packageIncludes) { var task = Task.Factory.StartNew(() => { var a = _manager.GetNumberOfMinutes(line, packageIncludes); return(a); }); return(await task.ConfigureAwait(false)); }
public async Task <LineDto> UpdateLine(int lineId, LineDto line) { Task <LineDto> lineDto; lock (_obj) { lineDto = _lineProvider.UpdateLine(lineId, line); } return(await lineDto); }
public async Task <LineDto> AddLine(LineDto newLine, SelectedNumberDto newSelectedNumber) { Task <LineDto> lineDto; lock (_obj) { lineDto = _lineProvider.AddLine(newLine, newSelectedNumber); } return(await lineDto); }
public async Task <IActionResult> Add(LineDto dto) { var result = await lineService.Add(dto); lineManager.Add(dto); return(Ok(new JsonResultDto <string> { Data = result, Message = string.IsNullOrEmpty(result) ? null : "操作失败" })); }
//public Result<LineDto> New(object criteria) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // var dto = new LineDto() // { // Id = Guid.NewGuid(), // LanguageId = SeedData.Ton.DefaultLanguageId // }; // retResult = Result<LineDto>.Success(dto); // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, ex); // } // return retResult; //} //public Result<LineDto> Fetch(Guid id) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // var results = from item in SeedData.Ton.Lines // where item.Id == id // select item; // if (results.Count() == 1) // retResult = Result<LineDto>.Success(results.First()); // else // { // if (results.Count() == 0) // retResult = Result<LineDto>.FailureWithInfo(null, // new Exceptions.FetchFailedException(DalResources.ErrorMsgIdNotFoundException)); // else // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.FetchFailedException()); // } // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, ex); // } // return retResult; //} //public Result<LineDto> Update(LineDto dto) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // var results = from item in SeedData.Ton.Lines // where item.Id == dto.Id // select item; // if (results.Count() == 1) // { // var LineToUpdate = results.First(); // SeedData.Ton.Lines.Remove(LineToUpdate); // dto.Id = Guid.NewGuid(); // SeedData.Ton.Lines.Add(dto); // retResult = Result<LineDto>.Success(dto); // } // else // { // if (results.Count() == 0) // retResult = Result<LineDto>.FailureWithInfo(null, // new Exceptions.UpdateFailedException(DalResources.ErrorMsgIdNotFoundException)); // else // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.FetchFailedException()); // } // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, ex); // } // return retResult; //} //public Result<LineDto> Insert(LineDto dto) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // var results = from item in SeedData.Ton.Lines // where item.Id == dto.Id // select item; // if (results.Count() == 0) // { // dto.Id = Guid.NewGuid(); // //MIMIC LANGUAGEID REQUIRED CONSTRAINT IN DB // if (dto.LanguageId == Guid.Empty || !SeedData.Ton.ContainsLanguageId(dto.LanguageId)) // { // //I'VE RESTRUCTURED HOW TO DO EXCEPTIONHANDLING, SO THIS IS NOT QUITE HOW IT SHOULD BE DONE. // //THIS SHOULD BE AN INSERTIMPL METHOD, AND IT SHOULD THROW ITS OWN EXCEPTION THAT IS WRAPPED IN THE // //PHRASEDALBASE CLASS IN AN INSERTFAILEDEXCEPTION. // throw new Exceptions.InsertFailedException(string.Format(DalResources.ErrorMsgIdNotFoundException, dto.LanguageId)); // } // SeedData.Ton.Lines.Add(dto); // retResult = Result<LineDto>.Success(dto); // } // else // { // if (results.Count() == 1) //ID ALREADY EXISTS // retResult = Result<LineDto>.FailureWithInfo(dto, // new Exceptions.UpdateFailedException(DalResources.ErrorMsgIdNotFoundException)); // else //MULTIPLE IDS ALREADY EXIST?? // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.FetchFailedException()); // } // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, ex); // } // return retResult; //} //public Result<LineDto> Delete(Guid id) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // var results = from item in SeedData.Ton.Lines // where item.Id == id // select item; // if (results.Count() == 1) // { // var LineToRemove = results.First(); // SeedData.Ton.Lines.Remove(LineToRemove); // retResult = Result<LineDto>.Success(LineToRemove); // } // else // { // if (results.Count() == 0) // retResult = Result<LineDto>.FailureWithInfo(null, // new Exceptions.DeleteFailedException(DalResources.ErrorMsgIdNotFoundException)); // else // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.DeleteFailedException()); // } // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, ex); // } // return retResult; //} //public LearnLanguages.Result<ICollection<LineDto>> GetAll() //{ // Result<ICollection<LineDto>> retResult = Result<ICollection<LineDto>>.Undefined(null); // try // { // var allDtos = new List<LineDto>(SeedData.Ton.Lines); // retResult = Result<ICollection<LineDto>>.Success(allDtos); // } // catch (Exception ex) // { // retResult = Result<ICollection<LineDto>>.FailureWithInfo(null, ex); // } // return retResult; //} protected override LineDto NewImpl(object criteria) { //to get to this point, we must have already been authenticated Debug.Assert(Csla.ApplicationContext.User.Identity.IsAuthenticated); //if (!Csla.ApplicationContext.User.Identity.IsAuthenticated) // throw new Common.Exceptions.UserNotAuthenticatedException(); //var languageId = SeedData.Ton.DefaultLanguageId; if (criteria != null) { throw new ArgumentException("criteria expected to be null"); } //if (criteria is string) //{ // //IF WE HAVE A STRING PARAM, THEN IT IS LANGUAGETEXT, SO GET THE LANGUAGE ID FROM THAT // var languageText = (string)criteria; // var languageResults = (from language in SeedData.Ton.Languages // where language.Text == languageText // select language); // if (languageResults.Count() == 1) // { // var languageDto = languageResults.First(); // languageId = languageDto.Id; // } // else if (languageResults.Count() == 0) // throw new Exceptions.LanguageTextNotFoundException(languageText); // else // throw new Exceptions.VeryBadException(); //} var username = Csla.ApplicationContext.User.Identity.Name; var userId = (from u in SeedData.Ton.Users where u.Username == username select u.Id).FirstOrDefault(); if (userId == Guid.Empty) { throw new Exceptions.UserNotAuthorizedException(); } var dto = new LineDto() { Id = Guid.NewGuid(), LineNumber = -1, UserId = userId, Username = username }; return(dto); }
public static LineDto ToDto(LineData data) { var dto = new LineDto() { Id = data.Id, LineNumber = data.LineNumber, PhraseId = data.PhraseDataId, UserId = data.UserDataId, Username = data.UserData.Username }; return(dto); }
internal ILine CreateLine(LineDto lineDto) { Constants.LineDirection runDirection = ConvertStringToLineDirection(lineDto.RunDirection); var line = new Line(lineDto.Id, lineDto.X1, lineDto.Y1, lineDto.X2, lineDto.Y2, runDirection, lineDto.IsUnknown); return line; }
public async Task <IActionResult> Create(LineDto create) { if (_lineService.GetById(create.ID) != null) { return(BadRequest("Line ID already exists!")); } create.CreatedDate = DateTime.Now; if (await _lineService.Add(create)) { return(NoContent()); } throw new Exception("Creating the model name failed on save"); }
public LinesViewModel(INavigationService navigationService) { _navigationService = navigationService; Line = new LineModel(); var task = Task.Factory.StartNew(() => GetLines()); Lines = new ObservableCollection <LineModel>(task.Result.Result); LineDto dto = server.GetLineAsync(Line.Number).Result; LineModel model = dto.ToModel(); dto.Package = model.Package.ToDto(); }
public static LineModel ToModel(this LineDto line) { return(new LineModel() { ClientId = line.ClientId, LineId = line.LineId, Number = line.Number, PackageId = line.PackageId, Status = line.Status, //Calls = line.Calls.Select(c => c.ToModel()).ToList(), Client = line.Client.ToModel(), //Package = line.Package.ToModel(), //SMS = line.SMS.Select(s => s.ToModel()).ToList() }); }
public static void LoadDataFromDto(ref LineData data, LineDto dto, LearnLanguagesContext context) { //USER INFO data.UserDataId = dto.UserId; data.UserData = EfHelper.GetUserData(dto.UserId, context); //PHRASE INFO data.PhraseDataId = dto.PhraseId; data.PhraseData = EfHelper.GetPhraseData(dto.PhraseId, context); //TEXT data.LineNumber = dto.LineNumber; }
public OptimalPackageViewModel(ILineService lineService, INavigationService navigationService) { _lineService = lineService; _navigationService = navigationService; Customer = new CustomerDto(); Line = new LineDto(); Customer = new ObservableCollection <CustomerDto>(); Lines = new CustomObservableCollection <LineDto>(); var customerTask = Task.Factory.StartNew(() => _lineService.GetClients()); Customer = new ObservableCollection <CustomerDto>(customerTask.Result.Result); RaisePropertyChanged(nameof(Customer)); }
/// <summary> /// Adds the lineDto to the context, loading UserData and PhraseData into the newly /// created LineData. Does NOT save changes to the context. /// </summary> public static LineData AddToContext(LineDto dto, LearnLanguagesContext context) { //only creates, does not add to linedatas //var beforeCount = context.LineDatas.Count(); var newLineData = context.LineDatas.CreateObject(); //var afterCount = context.LineDatas.Count(); //assign properties newLineData.LineNumber = dto.LineNumber; newLineData.PhraseDataId = dto.PhraseId; newLineData.UserDataId = dto.UserId; context.LineDatas.AddObject(newLineData); return newLineData; }
private void CheckContraints(LineDto dto) { //REFERENTIAL INTEGRITY if (dto.PhraseId == Guid.Empty || !SeedData.Ton.ContainsPhraseId(dto.PhraseId)) { throw new Exceptions.IdNotFoundException(dto.PhraseId); } if (dto.UserId == Guid.Empty || !SeedData.Ton.ContainsUserId(dto.UserId)) { throw new Exceptions.IdNotFoundException(dto.UserId); } if (string.IsNullOrEmpty(dto.Username) || !(SeedData.Ton.GetUsername(dto.UserId) == dto.Username)) { throw new ArgumentException("dto.Username"); } }
protected override LineDto UpdateImpl(LineDto dto) { var currentUserId = Business.BusinessHelper.GetCurrentUserId(); using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) { var results = from lineData in ctx.ObjectContext.LineDatas where lineData.Id == dto.Id && lineData.UserDataId == currentUserId select lineData; if (results.Count() == 1) { var lineData = results.First(); EfHelper.LoadDataFromDto(ref lineData, dto, ctx.ObjectContext); ctx.ObjectContext.SaveChanges(); var updatedDto = EfHelper.ToDto(lineData); return updatedDto; } else { if (results.Count() == 0) throw new Exceptions.IdNotFoundException(dto.Id); else { //results.count is not one or zero. either it's negative, which would be framework absurd, or its more than one, //which means that we have multiple lines with the same id. this is very bad. var errorMsg = string.Format(DalResources.ErrorMsgVeryBadException, DalResources.ErrorMsgVeryBadExceptionDetail_ResultCountNotOneOrZero); throw new Exceptions.VeryBadException(errorMsg); } } } }
// ReSharper disable once UnusedParameter.Local private void AssertDtoEqualsLine(LineDto dto, ILine line) { Assert.True(dto.Id == line.Id, "Id - Expected: {0} Actual: {1}".Inject(dto.Id, line.Id)); Assert.True(Math.Abs(dto.X1 - line.X1) < Tolerance, "X1 - Expected: {0} Actual: {1}".Inject(dto.X1, line.X1)); Assert.True(Math.Abs(dto.Y1 - line.Y1) < Tolerance, "Y1 - Expected: {0} Actual: {1}".Inject(dto.Y1, line.Y1)); Assert.True(Math.Abs(dto.X2 - line.X2) < Tolerance, "X2 - Expected: {0} Actual: {1}".Inject(dto.X2, line.X2)); Assert.True(Math.Abs(dto.Y2 - line.Y2) < Tolerance, "Y2 - Expected: {0} Actual: {1}".Inject(dto.Y2, line.Y2)); Assert.True(dto.RunDirection == line.RunDirection.ToString(), "RunDirection - Expected: {0} Actual: {1}".Inject(dto.RunDirection, line.RunDirection)); Assert.True(dto.IsUnknown == line.IsUnknown, "IsUnknown - Expected: {0} Actual: {1}".Inject(dto.IsUnknown, line.IsUnknown)); }
private void AssertDtosEqualLines(LineDto[] lineDtos, IEnumerable <ILine> lines) { foreach ( ILine line in lines ) { LineDto dto = lineDtos.FirstOrDefault(x => x.Id == line.Id); Assert.NotNull(dto); AssertDtoEqualsLine(dto, line); } }
private static LineDto CreateLineDto(int id, string runDirection, bool isUnknown) { var dto = new LineDto { Id = id, X1 = 1.0 + id, Y1 = 2.0 + id, X2 = 3.0 + id, Y2 = 4.0 + id, RunDirection = runDirection, IsUnknown = isUnknown }; return dto; }
public static LineDto ToDto(LineData data) { var dto = new LineDto() { Id = data.Id, LineNumber = data.LineNumber, PhraseId = data.PhraseDataId, UserId = data.UserDataId, Username = data.UserData.Username }; return dto; }
//public Result<LineDto> New(object criteria) //{ // //throw new NotImplementedException("Ef.LineDal.New(object)"); // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.CreateFailedException(ex)); // } // return retResult; //} //public Result<LineDto> Fetch(Guid id) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) // { // var results = from lineData in ctx.ObjectContext.LineDatas // where lineData.Id == id // select lineData; // if (results.Count() == 1) // retResult = Result<LineDto>.Success(EfHelper.ToDto(results.First())); // else // { // if (results.Count() == 0) // retResult = Result<LineDto>.FailureWithInfo(null, // new Exceptions.FetchFailedException(DalResources.ErrorMsgIdNotFound)); // else // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.FetchFailedException()); // } // } // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.FetchFailedException(ex)); // } // return retResult; //} //public Result<LineDto> Update(LineDto dto) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) // { // var results = from lineData in ctx.ObjectContext.LineDatas // where lineData.Id == dto.Id // select lineData; // if (results.Count() == 1) // { // var lineDataToUpdate = results.First(); // ctx.ObjectContext.LineDatas.DeleteObject(lineDataToUpdate); // var newLineData = EfHelper.ToData(dto); // ctx.ObjectContext.LineDatas.AddObject(newLineData); // ctx.ObjectContext.SaveChanges(); // dto.Id = newLineData.Id; // retResult = Result<LineDto>.Success(dto); // } // else // { // if (results.Count() == 0) // retResult = Result<LineDto>.FailureWithInfo(null, // new Exceptions.UpdateFailedException(DalResources.ErrorMsgIdNotFound)); // else // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.UpdateFailedException()); // } // } // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.UpdateFailedException(ex)); // } // return retResult; //} //public Result<LineDto> Insert(LineDto dto) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) // { // var results = from lineData in ctx.ObjectContext.LineDatas // where lineData.Id == dto.Id // select lineData; // //SHOULD FIND ZERO LANGUAGEDTOS (NO DUPLICATE IDS, NO DUPLICATE DTOS) // if (results.Count() == 0) // { // var data = EfHelper.ToData(dto); // ctx.ObjectContext.LineDatas.AddObject(data); // ctx.ObjectContext.SaveChanges(); // dto.Id = data.Id; // retResult = Result<LineDto>.Success(dto); // } // else // { // if (results.Count() == 1) //ID ALREADY EXISTS // retResult = Result<LineDto>.FailureWithInfo(dto, // new Exceptions.InsertFailedException(DalResources.ErrorMsgIdNotFound)); // else //MULTIPLE IDS ALREADY EXIST?? SHOULD NOT BE POSSIBLE // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.InsertFailedException()); // } // } // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.InsertFailedException(ex)); // } // return retResult; //} //public Result<LineDto> Delete(Guid id) //{ // Result<LineDto> retResult = Result<LineDto>.Undefined(null); // try // { // using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) // { // var results = from lineData in ctx.ObjectContext.LineDatas // where lineData.Id == id // select lineData; // if (results.Count() == 1) // { // var lineDataToRemove = results.First(); // ctx.ObjectContext.LineDatas.DeleteObject((lineDataToRemove)); // ctx.ObjectContext.SaveChanges(); // retResult = Result<LineDto>.Success(EfHelper.ToDto(lineDataToRemove)); // } // else // { // if (results.Count() == 0) // retResult = Result<LineDto>.FailureWithInfo(null, // new Exceptions.DeleteFailedException(DalResources.ErrorMsgIdNotFound)); // else // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.DeleteFailedException()); // } // } // } // catch (Exception ex) // { // retResult = Result<LineDto>.FailureWithInfo(null, new Exceptions.DeleteFailedException(ex)); // } // return retResult; //} //public Result<ICollection<LineDto>> GetAll() //{ // var retAllLineDtos = new List<LineDto>(); // using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) // { // var allLineDatas = from lineData in ctx.ObjectContext.LineDatas // select lineData; // foreach (var lineData in allLineDatas) // { // var lineDto = EfHelper.ToDto(lineData); // retAllLineDtos.Add(lineDto); // } // //var allDtos = new List<LineDto>(ctx.ObjectContext.LineDatas); // return retAllLineDtos; // } //} protected override LineDto NewImpl(object criteria) { var identity = (UserIdentity)Csla.ApplicationContext.User.Identity; string currentUsername = identity.Name; Guid currentUserId = Guid.Empty; using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) { currentUserId = (from user in ctx.ObjectContext.UserDatas where user.Username == currentUsername select user.Id).First(); } LineDto newLineDto = new LineDto() { Id = Guid.NewGuid(), PhraseId = Guid.Empty, UserId = currentUserId, Username = currentUsername }; return newLineDto; }
protected override LineDto InsertImpl(LineDto dto) { using (var ctx = LearnLanguagesContextManager.Instance.GetManager()) { var newLineData = EfHelper.AddToContext(dto, ctx.ObjectContext); ctx.ObjectContext.SaveChanges(); dto.Id = newLineData.Id; return dto; } }