public async Task <ItemGroupDto> GetAsync(Guid groupId, bool includeTasks = true) { var userId = _currentUserService.GetCurrentUser().Id; var group = await _itemGroupRepository.GetAsync(userId, groupId); if (group is null) { throw new GroupIdInvalidException(); } var taskDtos = new List <TaskDto>(); if (includeTasks) { var tasks = await _taskRepository.GetTasksInGroupAsync(groupId); foreach (var taskEntity in tasks) { taskDtos.Add(new TaskDto(taskEntity.Id, taskEntity.Name, taskEntity.Created, taskEntity.IsComplete, taskEntity.GroupId)); } } var groupDto = new ItemGroupDto(group.Id, group.Name, group.Description, group.ImageUri, taskDtos); return(groupDto); }
public List <ItemGroupDto> GetAndEditItemGroup(int GroupId, int IsActive) { List <ItemGroupDto> lstItemGroupDto = new List <ItemGroupDto>(); SqlCommand cmd = new SqlCommand("GetAndEditItemGroup", connectionRepository.con); cmd.Parameters.AddWithValue("@GroupId", GroupId); cmd.Parameters.AddWithValue("@IsActive", IsActive); cmd.CommandType = CommandType.StoredProcedure; connectionRepository.con.Open(); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { ItemGroupDto itemGroupDto = new ItemGroupDto(); itemGroupDto.GroupId = Convert.ToInt32(dr["GroupId"]); itemGroupDto.GroupName = Convert.ToString(dr["GroupName"]); itemGroupDto.GroupDesc = Convert.ToString(dr["GroupDesc"]); itemGroupDto.GroupImage = Convert.ToString(dr["GroupImage"]); itemGroupDto.CreatedBy = Convert.ToInt32(dr["CreatedBy"]); itemGroupDto.CreatedDate = Convert.ToString(dr["CreatedDate"]); itemGroupDto.ModifiedBy = Convert.ToInt32(dr["ModifiedBy"] != DBNull.Value ? dr["ModifiedBy"] : 0); itemGroupDto.ModifiedDate = Convert.ToString(dr["ModifiedDate"] != DBNull.Value ? dr["ModifiedDate"] : ""); itemGroupDto.IsActive = Convert.ToInt32(dr["IsActive"]); lstItemGroupDto.Add(itemGroupDto); } connectionRepository.con.Close(); return(lstItemGroupDto); }
public async Task <ActionResult> Add(ItemGroupDto model) { if (ModelState.IsValid) { var departmentId = await _itemService.AddItemGroup(model); if (departmentId.IsNotBlank()) { return(PartialView("CloseLayerPartial")); } } return(View(model)); }
/// <summary> /// /// </summary> /// <returns></returns> public async Task <ActionResult> Add(string id) { var parent = await _itemService.FindItemGroupByIdAsync(id); var model = new ItemGroupDto { ParentItemGroupId = id }; if (parent != null) { model.ParentItemGroupText = parent.ItemGroupText; } return(View(model)); }
/// <summary> /// 添加 ItemGroup 添加成功返回itemgroup主键,失败返回string.Empty /// </summary> /// <param name="dto"></param> /// <returns></returns> public async Task <string> AddItemGroup(ItemGroupDto dto) { var entity = _mapper.Map <ItemGroupEntity>(dto); entity.Init(); //var sss = _middleMDMContext.ItemGroups.Where(c => c.ItemGroupCode == dto.ItemGroupCode).ToList(); if (_context.ItemGroups.Any(c => c.ItemGroupCode == dto.ItemGroupCode)) { return(string.Empty); } await _context.ItemGroups.AddAsync(entity); await _context.SaveChangesAsync(); return(entity.Id); }
public ActionResult SaveItemGroup() { try { ItemGroupDal itemGroupDal = new ItemGroupDal(); ItemGroupDto itemGroupDto = new ItemGroupDto(); itemGroupDto.GroupId = Convert.ToInt32(System.Web.HttpContext.Current.Request["GroupId"] == "" ? "0" : System.Web.HttpContext.Current.Request["GroupId"]); string Message, fileName, actualFileName; Message = fileName = actualFileName = string.Empty; if (Request.Files.Count > 0) { var fileContent = Request.Files[0]; if (fileContent != null && fileContent.ContentLength > 0) { actualFileName = fileContent.FileName; fileName = Guid.NewGuid() + Path.GetExtension(fileContent.FileName); itemGroupDto.GroupImage = fileName; } fileContent.SaveAs(Path.Combine(Server.MapPath("~/UploadImages/"), fileName)); } else { fileName = ""; if (itemGroupDto.GroupId > 0) { dynamic imgFile = itemGroupDal.GetAndEditItemGroup(itemGroupDto.GroupId, 1); itemGroupDto.GroupImage = Convert.ToString(imgFile[0].GroupImage); } else { itemGroupDto.GroupImage = fileName; } } itemGroupDto.GroupName = System.Web.HttpContext.Current.Request["GroupName"]; itemGroupDto.GroupDesc = System.Web.HttpContext.Current.Request["GroupDesc"]; itemGroupDto.CreatedBy = Convert.ToInt32(Session["AdminId"]); itemGroupDto.ModifiedBy = Convert.ToInt32(Session["AdminId"]); itemGroupDto.IsActive = 1; int i = itemGroupDal.SaveItemGroup(itemGroupDto); return(Json(i, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { throw ex; } }
public async Task GetGroupsAsync_Always_HandlesResult(bool includeTasks) { //Arrange var sut = CreateSut(); var response = new Mock <IHttpResponse <IEnumerable <ItemGroupDto> > >(); Mocker.GetMock <IHttpClient>() .Setup(o => o.GetAsync <IEnumerable <ItemGroupDto> >(GroupUrls.GetGroupsUrl(includeTasks))) .ReturnsAsync(response.Object); var groupDto = new ItemGroupDto(Guid.NewGuid(), "", "", "", new List <TaskDto>()); Mocker.GetMock <IProxyHelper>() .Setup(o => o.ProcessResponseAsync(response.Object, sut)) .ReturnsAsync(new[] { groupDto }); //Act var result = await sut.GetGroupsAsync(includeTasks); //Assert result.Count().ShouldBe(1); }
public async Task GetAsync_Always_Gets() { //Arrange var sut = CreateSut(); var id = Guid.NewGuid(); var response = new Mock <IHttpResponse <ItemGroupDto> >(); Mocker.GetMock <IHttpClient>() .Setup(o => o.GetAsync <ItemGroupDto>(GroupUrls.GetGroupUrl(id, true))) .ReturnsAsync(response.Object); var groupDto = new ItemGroupDto(id, "", "", "", new List <TaskDto>()); Mocker.GetMock <IProxyHelper>() .Setup(o => o.ProcessResponseAsync(response.Object, sut)) .ReturnsAsync(groupDto); //Act var result = await sut.GetAsync(id, true); //Assert result.Id.ShouldBe(id); }
public int SaveItemGroup(ItemGroupDto itemGroupDto) { try { SqlCommand cmd = new SqlCommand("SaveAndUpdateItemGroup", connectionRepository.con); cmd.Parameters.AddWithValue("@GroupId", itemGroupDto.GroupId); cmd.Parameters.AddWithValue("@GroupName", itemGroupDto.GroupName); cmd.Parameters.AddWithValue("@GroupDesc", itemGroupDto.GroupDesc); cmd.Parameters.AddWithValue("@GroupImage", itemGroupDto.GroupImage); cmd.Parameters.AddWithValue("@CreatedBy", itemGroupDto.CreatedBy); cmd.Parameters.AddWithValue("@ModifiedBy", itemGroupDto.ModifiedBy); cmd.Parameters.AddWithValue("@IsActive", itemGroupDto.IsActive); cmd.CommandType = CommandType.StoredProcedure; connectionRepository.con.Open(); int i = cmd.ExecuteNonQuery(); connectionRepository.con.Close(); return(i); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> GetGroupAsync([FromQuery] Guid groupId, [FromQuery] bool includeTasks) { ItemGroupDto groupDto = await _itemGroupService.GetAsync(groupId, includeTasks); return(Ok(groupDto)); }