public async Task <IActionResult> OnPostAsync() { GameTitles = await _boxService.GetGameTitlesAsync(); var newBox = new BoxDTO(); if (await _boxService.DoesBoxExistAsync(Box.BoxId)) { ToastMessage = _locService.GetLocalizedString("Box with that code is already registered!"); ToastType = "error"; } else if (await TryUpdateModelAsync <BoxDTO>( newBox, "box", b => b.BoxId, b => b.GameId)) { await _boxService.AddBoxAsync(newBox); ToastMessage = _locService.GetLocalizedString("Record added"); ToastType = "success"; _logger.LogWarning($"Box with id '{newBox.BoxId}' for game with id '{newBox.GameId}' was created by '{User.Identity.Name}'."); return(RedirectToPage("./Create")); } return(Page()); }
//Output information of created box public ActionResult RequestBox(BoxModel viewModel) { //Show a view consisting of the fields of the box if (ModelState.IsValid) { string message = string.Format("The request for box with with size {0}:{1}:{2} and weight {3}, color {4} and material {5} was successfully accepted." , viewModel.Width, viewModel.Height, viewModel.Length, viewModel.Weight, viewModel.Colour, viewModel.Material); //Create DTO BoxDTO box = new BoxDTO(); //Set Properties of DTO foreach (PropertyInfo property in box.GetType().GetProperties()) { property.SetValue(box, viewModel.GetType().GetProperty(property.Name).GetValue(viewModel)); } _service.Insert(box); ViewBag.SuccessMessage = message; return(View()); } //Go back to creating a box, because something was not valid else { TempData["viewModel"] = viewModel; return(RedirectToAction("Create")); } }
public void AddBox(BoxDTO box, int id) { string login = HttpContext.Session.GetString("User_Login"); BoxesService service = new BoxesService(services); service.AddBox(box, id, login); }
public void AddBox(BoxDTO box, int training_id, string login) { Training training = db.Trainings.Get(training_id); if (training != null && training.Course.Coach_Login == login) { Box new_box = new Box() { Name = box.Name, Description = box.Text, Training_ID = training_id, Num_in_Training = training.Boxes.Count() }; db.Boxes.Create(new_box); db.Save(); if (box.IsMedia) { Media media = new Media() { Link = box.Link, Box_ID = new_box.ID }; db.Medias.Create(media); } else { db.Motions.Create(new Motion() { Box_ID = new_box.ID }); } db.Save(); } }
public JsonResult SaveNew(BoxDTO dto) { bool succeeded = false; try { var model = new tbl_boxes(); model.box_active = dto.box_active; model.box_brand = dto.box_brand; model.box_desc = dto.box_brand; model.box_hght = dto.box_hght; model.box_lngth = dto.box_lngth; model.box_wdth = dto.box_wdth; model.box_wght = dto.box_wght; UnitOfWork.TblBox.Add(model); UnitOfWork.Save(); dto.id = model.id; } catch (Exception ex) { dto.id = 0; } return(Json(dto, JsonRequestBehavior.AllowGet)); }
public JsonResult Update(BoxDTO dto) { bool succeeded = false; try { var model = UnitOfWork.TblBox.Get(dto.id); if (model != null) { model.box_active = dto.box_active; model.box_brand = dto.box_brand; model.box_desc = dto.box_desc; model.box_hght = dto.box_hght; model.box_lngth = dto.box_lngth; model.box_wdth = dto.box_wdth; model.box_wght = dto.box_wght; UnitOfWork.Save(); succeeded = true; } } catch (Exception ex) { succeeded = false; } return(Json(succeeded, JsonRequestBehavior.AllowGet)); }
public static void Update(BoxDTO updateBox) { try { databaseDataContext db = new databaseDataContext(); var find = (from box in db.Boxes where box.Id == updateBox.Id select box).Single(); find.PlanId = updateBox.PlanId; find.Width = updateBox.Width; find.Height = updateBox.Height; find.Depth = updateBox.Depth; find.BoardThickness = updateBox.BoardThickness; find.PositionX = updateBox.PositionX; find.PositionY = updateBox.PositionY; find.PositionZ = updateBox.PositionZ; find.Name = updateBox.Name; find.Texture = updateBox.Texture; find.vertikalno = updateBox.vertikalno; find.horizontalno = updateBox.horizontalno; find.globalX = updateBox.globalX; find.globalY = updateBox.globalY; find.globalZ = updateBox.globalZ; db.SubmitChanges(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public async Task UpdateBoxAsync(BoxDTO boxDTOtoUpdate) { var boxEntityToUpdate = await GetAsync(boxDTOtoUpdate.BoxId); _mapper.Map <BoxDTO, BoxEntity>(boxDTOtoUpdate, boxEntityToUpdate); await _context.SaveChangesAsync(); }
public void Insert(BoxDTO box) { ATPEntities _dbContext = new ATPEntities(); //Create connection _dbContext.BOX.Add(Convert(box)); //Add box to database _dbContext.SaveChanges(); //Save Changes to the database }//Adds a box to the database
//Get Details public ActionResult Details(int id) { BoxDTO boxDTO = _bs.GetBoxById(id).Result; if (boxDTO == null) { return(HttpNotFound()); } return(View(boxDTO)); }
public async Task <PartialViewResult> OnGetSelectBoxAsync(ulong?id) { BoxDTO boxDTO = null; if (id.HasValue) { boxDTO = await _boxService.GetBoxWithRelatedGameDataAsync(id.Value); } return(Partial("_Details", boxDTO)); }
public BOX Convert(BoxDTO dto) => new BOX { COLOR = dto.Colour, HEIGHT = dto.Height, LENGTH = dto.Length, MATERIAL = dto.Material, WEIGHT = dto.Width, WIDTH = dto.Weight, ID = dto.ID };
//DTO to Model Converter private BoxModel Convert(BoxDTO dto) => new BoxModel { Colour = dto.Colour, Height = dto.Height, ID = dto.ID, Length = dto.Length, Material = dto.Material, Weight = dto.Weight, Width = dto.Width };
public async Task <BoxDTO> UpdateBox(Guid id, BoxDTO modelDto) { var model = _mapper.Map <Box>(modelDto); model.Id = id; _context.Boxes.Update(model); await _context.SaveChangesAsync(); return(_mapper.Map <BoxDTO>(model)); }
public async Task <ActionResult> AjouterBox([FromBody] BoxDTO boxDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Box box = mapper.Map <Box>(boxDTO); box = await boxDAO.AjouterBox(box); return(Created($"api/Box/{box.Id}", mapper.Map <BoxDTO>(box))); }
public ActionResult Edit(BoxDTO boxDTO) { if (ModelState.IsValid) { // var result = _bs.UpdateBox(boxDTO.ID); var result = _bs.UpdateBox(boxDTO); return(RedirectToAction("Index", "AdminBox")); } GetViewBagData(); return(View(boxDTO)); }
public ActionResult Edit(int id) { var result = _bs.GetBoxById(id); BoxDTO boxDTO = result.Result; if (boxDTO == null) { return(HttpNotFound()); } GetViewBagData(); return(View("Edit", boxDTO)); }
}//Removes a box with the specified ID public void Edit(BoxDTO dto) { ATPEntities _dbContext = new ATPEntities(); //Create connection BOX old = _dbContext.BOX.Where(entity => entity.ID == dto.ID).FirstOrDefault(); //Get the old box BOX newBOX = Convert(dto); //Create a new box from a conversion foreach (PropertyInfo property in old.GetType().GetProperties().Where(property => property.Name != "ID")) { property.SetValue(old, property.GetValue(newBOX)); // set the values of the old box to the values of the new one } _dbContext.SaveChanges(); //Save Changes to the database }//Edit a box with the specified by the DTO ID
public static Box MappingBoxVMtoBoxEntity(BoxDTO BoxDTO) { Box box = new Box() { BoxName = BoxDTO.BoxName, BoxTypeID = BoxDTO.BoxTypeID, Description = BoxDTO.Description, ImageUrl = BoxDTO.ImageUrl, Price = BoxDTO.Price, UnitsInStock = BoxDTO.UnitsInStock }; return(box); }
public long Save(BoxDTO pBoxDTO) { long Result = 0; if (pBoxDTO.ID != 0) { Result = new BoxService().Edit(pBoxDTO); } else { Result = new BoxService().Add(pBoxDTO); } return(Result); }
public ServiceResult <AllBoxTypesWithBoxDTO> GetAllBoxTypesWithBox() { var boxTypeList = _btr.GetList(); var boxTypeListDTO = Helper.Helpers.Mapping <BoxType, BoxTypeDTO>(boxTypeList); BoxDTO boxDTO = new BoxDTO(); AllBoxTypesWithBoxDTO allBox = new AllBoxTypesWithBoxDTO() { BoxTypes = boxTypeListDTO, Box = boxDTO }; return(new ServiceResult <AllBoxTypesWithBoxDTO>(ProcessStateEnum.Success, "", allBox)); }
public async Task UpdateBoxAsync_updatesBox() { // Arrange: var boxDTOtoUpdate = new BoxDTO { BoxId = 4, GameId = 1 }; var service = new BoxService(Context, _mapper); // Act: await service.UpdateBoxAsync(boxDTOtoUpdate); // Assert: Assert.True(Context.Boxes.Count() == 4); Assert.True(Context.Boxes.FirstOrDefault(x => x.BoxId == 4).GameId == 1); }
public async Task ModifierBox(Box box, BoxDTO boxDTO) { box.Id = boxDTO.Id; box.Nom = boxDTO.Nom; box.PrixUnitaireHtva = boxDTO.PrixUnitaireHtva; box.Tva = boxDTO.Tva; box.Promotion = boxDTO.Promotion; box.Description = boxDTO.Description; box.Photo = boxDTO.Photo; box.Affichable = boxDTO.Affichable; box.DateCreation = boxDTO.DateCreation; context.Entry(box).OriginalValues["RowVersion"] = boxDTO.RowVersion; await context.SaveChangesAsync(); }
public ServiceResult AddBox(BoxDTO BoxDTO) { int ess = 0; Box box = new Box(); box = VMMappings.MappingBoxVMtoBoxEntity(BoxDTO); ess = _br.Add(box); if (ess > 0) { return(new ServiceResult(ProcessStateEnum.Success, "Kayıt başarılı")); } else { return(new ServiceResult(ProcessStateEnum.Warning, "Herhangi değişiklik algılanmadığından kayıt yapılmamıştır.")); } }
public static List <BoxDTO> BoxesInPlan(int planId) { List <BoxDTO> boxes = new List <BoxDTO>(); try { databaseDataContext db = new databaseDataContext(); var find = (from box in db.Boxes where box.PlanId == planId select box); foreach (var f in find) { BoxDTO boxRead = new BoxDTO() { Id = f.Id, PlanId = f.PlanId, Width = f.Width, Height = f.Height, Depth = f.Depth, BoardThickness = f.BoardThickness, PositionX = f.PositionX, PositionY = f.PositionY, PositionZ = f.PositionZ, Name = f.Name, Texture = f.Texture, vertikalno = f.vertikalno, horizontalno = f.horizontalno, globalX = f.globalX, globalY = f.globalY, globalZ = f.globalZ }; boxes.Add(boxRead); } } catch (Exception e) { Console.WriteLine(e.Message); } return(boxes); }
//Edit box with a specified BoxModel public ActionResult Edit(BoxModel viewModel) { if (ModelState.IsValid) { BoxDTO @new = new BoxDTO(); foreach (PropertyInfo property in @new.GetType().GetProperties()) { property.SetValue(@new, viewModel.GetType().GetProperty(property.Name).GetValue(viewModel)); } _service.Edit(@new); return(RedirectToAction("List")); } else { return(RedirectToAction("Edit", new { id = viewModel.ID })); } }
public BoxDTO GetByID(long ID) { var Result = new BoxDTO(); using (var Context = new BaseContext()) { var Box = Context.Boxes.FirstOrDefault(a => a.ID == ID); if (Box != null) { Result.ID = Box.ID; Result.Name = Box.Name; Result.BoxSize = Box.BoxSize; Result.BoxPlaceCount = Box.BoxPlaceCount; Result.Description = Box.Description; Result.DisplayOrder = Box.DisplayOrder; Result.ImageName = Box.ImageName; } } return(Result); }
public long Edit(BoxDTO pBoxDTO) { long BoxID = 0; using (var Context = new BaseContext()) { var Box = Context.Boxes.FirstOrDefault(a => a.ID == pBoxDTO.ID); if (Box != null) { Box.Name = pBoxDTO.Name; Box.BoxSize = pBoxDTO.BoxSize; Box.BoxPlaceCount = pBoxDTO.BoxPlaceCount; Box.Description = pBoxDTO.Description; Box.DisplayOrder = pBoxDTO.DisplayOrder; Context.SaveChanges(); BoxID = Box.ID; } } return(BoxID); }
public async Task AddNewBoxAsync_addsNewBox() { // Arrange: ulong boxId = 1234; var boxDTOtoAdd = new BoxDTO { BoxId = boxId, GameId = 4 }; var service = new BoxService(Context, _mapper); // Act: await service.AddBoxAsync(boxDTOtoAdd); // Assert: var addedBox = await service.GetBoxAsync(boxId); Assert.Equal(addedBox.BoxId, boxDTOtoAdd.BoxId); Assert.Equal(boxId, addedBox.BoxId); Assert.Equal(4, addedBox.GameId); Assert.True(await Context.Boxes.CountAsync() == 5); }
public long Add(BoxDTO pBoxDTO) { long BoxID = 0; using (var Context = new BaseContext()) { var Box = new BoxModel { Name = pBoxDTO.Name, BoxSize = pBoxDTO.BoxSize, BoxPlaceCount = pBoxDTO.BoxPlaceCount, Description = pBoxDTO.Description, DisplayOrder = pBoxDTO.DisplayOrder, Deleted = false }; Context.Boxes.Add(Box); Context.SaveChanges(); BoxID = Box.ID; } return(BoxID); }