public async Task UpdateUnitAsync(UnitDTO unitDTO) { var unit = await _unitRepository.GetByIdAsync(unitDTO.Id).ConfigureAwait(false); if (unit == null) { throw new TestExamplesException("Güncellenecek veri bulunamadı."); } unit.Name = unitDTO.Name; unit.Description = unitDTO.Description; await _unitRepository.Update(unit).ConfigureAwait(false); }
public static Unit FromDto(UnitDTO unitDto) { switch (unitDto.Type) { case UnitDTO.UnitType.Swordsman: Vector3 pos = new Vector3(unitDto.PosX, unitDto.PosY, unitDto.PosZ); Vector3 rotEuler = new Vector3(unitDto.RotX, unitDto.RotY, unitDto.RotZ); Quaternion rot = rotEuler.ToQuaternion(); return(new Swordsman(unitDto.Id, unitDto.OwnerId, pos, rot, unitDto.Weight, unitDto.Scale, unitDto.Health)); default: return(null); } }
/// <summary> /// Retrieves a unit from the database using provided unit id. /// </summary> /// <param name="id">The id of the unit to retrieve.</param> /// <returns></returns> public UnitDTO GetUnit(int id) { UnitDTO dto = null; using (helpdesksystemContext context = new helpdesksystemContext()) { var unit = context.Unit.Include("Topic").FirstOrDefault(u => u.UnitId == id); if (unit != null) { dto = DAO2DTO(unit); } } return(dto); }
public void Edit(UnitDTO DTO) { using (var container = new InventoryContainer()) { var Comp = new Unit(); Comp = container.Units.FirstOrDefault(o => o.UnitId.Equals(DTO.UnitId)); Comp.UnitId = DTO.UnitId; Comp.UnitName = DTO.UnitName; Comp.UpdateBy = DTO.UpdateBy; Comp.UpdateDate = DTO.UpdateDate; Comp = (Unit)DTOMapper.DTOObjectConverter(DTO, Comp); container.SaveChanges(); } }
public UnitDTO GetUnitById(int id) { IMapper mapperWorker = new MapperConfiguration(cfg => cfg.CreateMap <Unit, UnitDTO>()).CreateMapper(); Unit unit = unitOfWork.Units.Get(id); if (unit == null) { return(null); } UnitDTO unitDTO = mapperWorker.Map <Unit, UnitDTO>(unit); return(unitDTO); }
private UnitDTO ToDto(UnitEntity entity) { var dto = new UnitDTO() { Name = entity.Name, Id = entity.Id, CreateTime = entity.CreateTime, Address = entity.Address, LinkMan = entity.LinkMan, Tel = entity.Tel, PhoneNum = entity.PhoneNum, }; return(dto); }
public async Task AddUnitAsync(UnitDTO unitDTO) { if (unitDTO == null) { throw new TestExamplesException("Eklenecek birim boş olamaz."); } var unit = new Unit { Description = unitDTO.Description, Name = unitDTO.Name }; await _unitRepository.AddAsync(unit).ConfigureAwait(false); }
public int updateUnit(UnitDTO unit) { string sql = string.Format(" update DONVITINH " + " set Ten = N'{0}', GhiChu = N'{1}', Active = N'{2}' " + " where MaDVT = '{3}' ", unit.iTen, unit.iGhiChu, unit.iActive, unit.iMaDVT); try { ConnectionDB.ExecNonQuery(sql); return(1); } catch { return(0); } }
/// <summary> /// Retrieves a unit from the database using provided unit code. /// </summary> /// <param name="code">The name of the unit to retrieve.</param> /// <returns>The unit DTO</returns> public UnitDTO GetUnitByCodeAndHelpdeskId(string code, int helpdeskId) { UnitDTO dto = null; using (helpdesksystemContext context = new helpdesksystemContext()) { var unitIds = context.Helpdeskunit.Where(hu => hu.HelpdeskId == helpdeskId).Select(u => u.UnitId).ToList(); var unit = context.Unit.Include("Helpdeskunit").Include("Topic").FirstOrDefault(u => u.Code.Equals(code) && unitIds.Contains(u.UnitId)); if (unit != null) { dto = DAO2DTO(unit); } } return(dto); }
public int insertUnit(UnitDTO unit) { string id = IDAuto(); string sql = string.Format(" insert into DONVITINH (MaDVT, Ten, GhiChu, Active) values" + "('{0}', N'{1}', N'{2}', N'{3}')", id, unit.iTen, unit.iGhiChu, unit.iActive); try { ConnectionDB.ExecNonQuery(sql); return(1); } catch { return(0); } }
public List <UnitDTO> getUnit() { string sql = "SELECT * FROM DONVITINH"; DataTable data = ConnectionDB.getData(sql); List <UnitDTO> list = new List <UnitDTO>(); for (int i = 0; i < data.Rows.Count; i++) { UnitDTO unit = new UnitDTO(); unit.iMaDVT = data.Rows[i]["MaDVT"].ToString(); unit.iTen = data.Rows[i]["Ten"].ToString(); unit.iGhiChu = data.Rows[i]["GhiChu"].ToString(); unit.iActive = bool.Parse(data.Rows[i]["Active"].ToString()); list.Add(unit); } return(list); }
public List <UnitDTO> GetAllUnits() { using (var context = new MSSContext()) { var Units = from aUnit in context.units select aUnit; List <UnitDTO> unitDTOs = new List <UnitDTO>(); foreach (unit unit in Units) { UnitDTO temp = new UnitDTO(); temp.unitid = unit.unitid; temp.unitname = unit.unitname; unitDTOs.Add(temp); } return(unitDTOs); } }
public async Task <UnitDTO> GetByIdUnitAsync(int id) { var unit = await _unitRepository.GetByIdAsync(id).ConfigureAwait(false); if (unit == null) { throw new TestExamplesException("Silinecek birim bulunamadı tekrar deneyiniz."); } var unitDTO = new UnitDTO { Description = unit.Description, Name = unit.Name }; return(unitDTO); }
/// <summary> /// Создает новую единицу измерения /// </summary> /// <param name="model">Модель единицы измерения</param> /// <returns></returns> public bool Create(UnitDTO model) { var url = new Uri($"{this.url}/unit/create"); var json = JsonConvert.SerializeObject(model); var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/json"; using (var dataStream = new StreamWriter(request.GetRequestStream())) { dataStream.Write(json); dataStream.Close(); } var responce = (HttpWebResponse)request.GetResponse(); return(responce.StatusCode == HttpStatusCode.Created ? true : false); }
public List <UnitDTO> GetActiveCareSiteUnits(int careSiteId) { using (var context = new MSSContext()) { var careSiteUnits = from aUnit in context.units where aUnit.caresiteid == careSiteId && aUnit.activeyn == true select aUnit; List <UnitDTO> unitDTOs = new List <UnitDTO>(); foreach (unit unit in careSiteUnits) { UnitDTO temp = new UnitDTO(); temp.unitid = unit.unitid; temp.unitname = unit.unitname; unitDTOs.Add(temp); } return(unitDTOs); } }
public List <UnitDTO> GetUnits() { using (UnitOfWork uow = new UnitOfWork()) { var units = uow.Units.List(); List <UnitDTO> unitList = new List <UnitDTO>(); foreach (var item in units) { UnitDTO unit = Mapper.Map <Unit, UnitDTO>(item); unitList.Add(unit); } return(unitList); } }
private void CreateUnit() { unitApi = new UnitAPI(); var model = new UnitDTO() { Name = this.name, Symbol = this.symbol }; var resultFlag = unitApi.Create(model); if (resultFlag) { MessageBox.Show("Успешно создано."); } if (!resultFlag) { MessageBox.Show("Ошибка при создании."); } }
private void btnSave_Click(object sender, EventArgs e) { UnitDTO unit = new UnitDTO(); unit.iTen = txtTen.Text; unit.iGhiChu = txtGhiChu.Text; unit.iActive = bool.Parse(checkBoxActive.Checked.ToString()); int check = b_unit.insertUnit(unit); if (check == 1) { XtraMessageBox.Show("Thêm đơn vị tính " + unit.iMaDVT + " thành công!!!"); frmUnit.statusAction = 1; this.Close(); } else { XtraMessageBox.Show("Thêm đơn vị tính " + unit.iMaDVT + " thất bại!!!"); } }
private void EditUnit() { unitApi = new UnitAPI(); var model = new UnitDTO() { Id = this.id, Name = this.name, Symbol = this.symbol }; var resultFlag = unitApi.Update(model); if (resultFlag) { MessageBox.Show("Успешно сохранено."); } if (!resultFlag) { MessageBox.Show("Не удачно."); } }
public async Task <ActionResult> AddUnit(string description) { // Call BLL Unit Add method with all the parameters object BLLResponse = new UnitBLL(_context).AddUnitBLL(description: description); if (BLLResponse.GetType().BaseType == typeof(Exception)) { // Create log entries for Debug log ((APIException)BLLResponse).Exceptions.ForEach(ex => Logger.Msg <UnitsController>((Exception)ex, Serilog.Events.LogEventLevel.Debug)); // Return response from API return(BadRequest(new { errors = ((APIException)BLLResponse).Exceptions.Select(x => x.Message).ToArray() })); } else { try { Unit newUnit = new Unit { Description = ((UnitDTO)BLLResponse).Description }; // Create the record _context.Units.Add(newUnit); await _context.SaveChangesAsync(); Logger.Msg <UnitsController>($"[{User.FindFirstValue("email")}] [ADD] Unit '{description}' successful", Serilog.Events.LogEventLevel.Information); // Convert back to DTO and return to user UnitDTO response = new UnitDTO(newUnit); return(Ok(response)); } catch (Exception ex) { // Local log entry. Database reconciliation issues are more serious so reported as Error Logger.Msg <UnitsController>($"[ADD] Database sync error {ex.Message}", Serilog.Events.LogEventLevel.Error); // Return response to client return(StatusCode(500, new { errors = "Database update failed. Contact the administrator to resolve this issue." })); } } } // End of AddUnit
public void Load(UnitDTO unitParam, ActionType actionTypeParam) { actionType = actionTypeParam; if (actionType == ActionType.ModifyUnit) { ShowBusyIndicator(); unitService.GetUnit((res, exp) => appController.BeginInvokeOnDispatcher(() => { HideBusyIndicator(); if (exp == null) { Unit = res; } else { appController.HandleException(exp); } }), unitParam.Id); } }
public async Task UnitService_Should_Create_Unit_Async() { // Arrange SetUpUnitOfWork(); var service = new UnitService(_unitOfWork.Object, _mapper); var expectedEntity = new UnitDTO() { Name = "TestName", ShortName = "TestSN", }; // Act var actualEntity = await service.CreateAsync(expectedEntity); await _unitOfWork.Object.SaveAsync(); // Assert Assert.NotNull(actualEntity); Assert.Equal(expectedEntity.Name, actualEntity.Name); Assert.Equal(expectedEntity.ShortName, actualEntity.ShortName); }
private UnitInPeriodDTO createDestinationUnitInPeriod(UnitDTO unit, long?parentId) { var res = new UnitInPeriodDTO { Name = unit.Name, CustomFields = new List <CustomFieldDTO>(), UnitId = unit.Id, ParentId = parentId, UnitIndices = unitIndexInperiodList.Select(c => new UnitInPeriodUnitIndexDTO { Id = c.Id, Name = c.Name, IsInquireable = c.IsInquireable, ShowforLowLevel = true, ShowforSameLevel = true, ShowforTopLevel = true }).ToList() }; return(res); }
public async Task <IActionResult> CreateUnit(int groupId, string name, int unitTypeId, string noteText, int currentCapacity, int maxCapacity, int colorId, string street, string streetNumber, string city, string zip, string state, IFormFile contractFile) { var address = new Address { State = state ?? string.Empty, City = city ?? string.Empty, Street = street ?? string.Empty, Number = streetNumber ?? string.Empty, Zip = zip ?? string.Empty }; var spec = new Specification { Name = name ?? string.Empty, Note = noteText ?? string.Empty, ColorId = colorId, Address = address }; var unit = new UnitDTO { OwnerId = UserInfoManager.UserId, Specification = spec, UnitGroupId = groupId, UnitTypeId = unitTypeId, CurrentCapacity = currentCapacity, MaxCapacity = maxCapacity }; var contract = GetContract(contractFile, unit); unit.Contract = contract; await _unitFacade.CreateUnitAsync(unit); return(RedirectToAction("MyUnits", "Units", new { groupId })); }
public async Task <int> InsertUnitAsync(UnitDTO unit) { int id = 0; using (var connection = new SqlConnection(_connectionString)) { using (var cmd = new SqlCommand()) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "[dbo].[SpUnitCreate]"; cmd.Parameters.AddWithValue("BuildingId", unit.BuildingId); cmd.Parameters.AddWithValue("@Area", unit.Area); cmd.Parameters.AddWithValue("@UnitNumber", unit.UnitNumber); cmd.Connection = connection; cmd.Connection.Open(); var result = await cmd.ExecuteScalarAsync(); id = Convert.ToInt32(result); } } return(id); }
/* * CREATED: C. Stanhope MAR 2 2018 * MODIFIED: A. Valberg MAR 3 2018 * - Added method body code * MODIFIED: H. Conant MAR 5 2018 * - Updated method signature * - Updated method body code * * DeactivateUnitButton_Click() * This method allows the user to deactivate a specified unit in the database. * * PARAMETERS: * object sender - object on the page that is being targeted * EventArgs e - event that has triggered the method * * RETURNS: * void - Nothing is returned * * METHOD CALLS: * .IsNullOrWhiteSpace() * .TryParse() * UnitDTO() * .DeactivateUnit() * ClearPage(); */ protected void DeactivateUnitButton_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(DeactivateUnitNameLabel.Text)) { UserMessage.Text = "Please select a unit"; } else { int tempUnitId; int.TryParse(UnitDDL.SelectedValue, out tempUnitId); //UnitHiddenField.Value UnitDTO tempUnit = new UnitDTO(); tempUnit.unitid = tempUnitId; try { unitController.DeactivateUnit(tempUnit); ClearPage(); } catch (Exception ex) { ErrorMessage.Text = "Deactivate unit failed. Please contact the system administrator."; } } }
/* * CREATED: A. Valberg MAR 3 2018 * MODIFIED: H. Conant MAR 5 2018 * - Updated method signature * - Updated method body code * MODIFIED: H. Conant MAR 27 2018 * - Updated method body code * MODIFIED: H. L'Heureux APR 03 2018 * - Updated method body code * * AddUnitButton_Click() * This method allows the user to add a specified unit in the database. * * PARAMETERS: * object sender - object on the page that is being targeted * EventArgs e - event that has triggered the method * * RETURNS: * void * * ODEV METHOD CALLS: * MessageUserControl.ShowInfoMessage() * UnitController.AddUnit() * MessageUserControl.ShowSuccessMessage() * MessageUserControl.ShowErrorMessage() * ClearPage() */ protected void AddUnitButton_Click(object sender, EventArgs e) { string pattern = @"^[A-z 0-9 .-]{1,60}$"; Regex reg = new Regex(pattern); Match unitNameFormat = reg.Match(AddUnitNameTB.Text); if (string.IsNullOrWhiteSpace(AddUnitNameTB.Text) || AddUnitNameTB.Text.Length > 60 || !unitNameFormat.Success) { MessageUserControl.ShowInfoMessage("Please enter a unit name up to 60 characters. Unit names can only contain letters, numbers, and the following symbols: . -"); } else { int tempCareSiteID; int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteID); if (tempCareSiteID == 0) { MessageUserControl.ShowInfoMessage("Please select a care site."); } else { UnitDTO tempUnit = new UnitDTO(); tempUnit.caresiteid = tempCareSiteID; tempUnit.unitname = AddUnitNameTB.Text.Trim(); try { unitController.AddUnit(tempUnit); MessageUserControl.ShowSuccessMessage("Unit " + AddUnitNameTB.Text + " has been added to the " + CareSiteDDL.SelectedItem.Text + " care site."); ClearPage(); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Adding unit failed. Please try again. If error persists, please contact your administrator.", ex); } } } }
public void GetUnit() { var units = Module.IvUnitGetAll(); var list = new List <UnitDTO>(); foreach (IvUnit r in units) { var unitDto = new UnitDTO(); unitDto.Id = r.Id; unitDto.Math = r.Math; unitDto.Name = r.Name; unitDto.Note = r.Note; if (r.Parent != null) { unitDto.ParentId = r.Parent.Id; } unitDto.Rate = r.Rate; list.Add(unitDto); } HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(list)); }
public void Load(UnitDTO unitParam, ActionType actionTypeParam) { actionType = actionTypeParam; UnitDto = unitParam; ShowBusyIndicator(); customFieldService.GetAllCustomFieldsDescription((res, exp) => appController.BeginInvokeOnDispatcher(() => { if (exp == null) { UnitCustomFieldDescriptionList = res; if (actionType == ActionType.ManageUnitCustomFields) { setCurrentUnitCustomFields(); } HideBusyIndicator(); } else { HideBusyIndicator(); appController.HandleException(exp); } }), "Unit"); }
public async Task UnitService_Should_Delete_Unit_Async() { // Arrange SetUpUnitOfWork(); var service = new UnitService(_unitOfWork.Object, _mapper); var entity = new UnitDTO() { Name = "TestName", ShortName = "TestSN", }; entity = await service.CreateAsync(entity); await _unitOfWork.Object.SaveAsync(); // Act await service.DeleteAsync(entity.Id); await _unitOfWork.Object.SaveAsync(); // Assert Assert.Null(await service.GetAsync(entity.Id)); }