Exemple #1
0
        // TODO: penamaan routing tidak konsisten: ada yang PascalCase, lowercase, dan null
        public async Task <IActionResult> CreateData(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "create/data")] HttpRequest req,
            [RequestBodyType(typeof(DTOClass), "Create request")]
            ILogger log)
        {
            try
            {
                var content = await new StreamReader(req.Body).ReadToEndAsync();

                DTOClass myClass = JsonConvert.DeserializeObject <DTOClass>(content);

                if (myClass.ClassCode == null || myClass.ClassCode == null)
                {
                    return(new BadRequestResult());
                }

                var body = new DTOClass
                {
                    ClassCode   = myClass.ClassCode,
                    Description = myClass.Description,
                };
                var data = await _fetchServices.CreateNewDtoClass(body);

                var mappedData = _mapper.Map <ClassDTO>(data);
                return(new OkObjectResult(mappedData));
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult(e.Message));
            }
        }
        public async Task <IActionResult> UpdateDataById(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "update/data/{id}")] HttpRequest req,
            [RequestBodyType(typeof(DTOClass), "Update request")]
            string id,
            ILogger log)
        {
            var content = await new StreamReader(req.Body).ReadToEndAsync();

            DTOClass myClass = JsonConvert.DeserializeObject <DTOClass>(content);

            if (myClass.ClassCode == null || myClass.ClassCode == null)
            {
                return(new BadRequestObjectResult("Input not complete"));
            }

            try
            {
                var dataCurrent = await _fetchServices.GetDtoClassById(id);

                if (dataCurrent == null)
                {
                    return(new NotFoundObjectResult("Data doesn't exist"));
                }
                dataCurrent.Description = myClass.Description;
                dataCurrent.ClassCode   = myClass.ClassCode;
                var data = await _fetchServices.UpdateDtoClas(id, dataCurrent);

                var mappedData = _mapper.Map <ClassDTO>(data);
                return(new OkObjectResult(mappedData));
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult(e.Message));
            }
        }
Exemple #3
0
        public void SuaLop(DTOClass L)
        {
            OpenConnect();
            string     edit = "update [QLDSV].[QLDSV].[Class] set tenlop=@NameClass, tenkhoa=@NameFaculty where malop=@CodeClass";
            SqlCommand cmd  = new SqlCommand(edit, conn);

            cmd.Parameters.Add(new SqlParameter("@CodeClass", L.MaLop));
            cmd.Parameters.Add(new SqlParameter("@NameClass", L.TenLop));
            cmd.Parameters.Add(new SqlParameter("@NameFaculty", L.TenKhoa));
            cmd.ExecuteNonQuery();
            CloseConnect();
        }
Exemple #4
0
        public void ThemLop(DTOClass L)
        {
            OpenConnect();
            string     insert = "insert into [QLDSV].[QLDSV].[Class] values (@CodeClass, @NameClass, @NameFaculty)";
            SqlCommand cmd    = new SqlCommand(insert, conn);

            cmd.Parameters.Add(new SqlParameter("@CodeClass", L.MaLop));
            cmd.Parameters.Add(new SqlParameter("@NameClass", L.TenLop));
            cmd.Parameters.Add(new SqlParameter("@NameFaculty", L.TenKhoa));
            cmd.ExecuteNonQuery();
            CloseConnect();
        }
Exemple #5
0
            public async Task UpdateData(string id)
            {
                var repo = new Mock <IDocumentDBRepository <DTOClass> >();

                var data = new DTOClass
                {
                    Id          = "1",
                    ClassCode   = "codes-xx",
                    Description = "desc"
                };

                repo.Setup(c => c.UpdateAsync(
                               It.IsAny <string>(),
                               It.IsAny <DTOClass>(),
                               It.IsAny <EventGridOptions>(),
                               It.IsAny <string>()
                               )).Returns(Task.FromResult(data));

                var svc = new FetchService(repo.Object);

                var act = await svc.UpdateDtoClas(id, data);

                Assert.Equal(data.ClassCode, act.ClassCode);
            }
Exemple #6
0
 public async Task <DTOClass> UpdateDtoClas(string id, DTOClass dto)
 {
     return(await repository.UpdateAsync(id, dto));
 }
Exemple #7
0
 public async Task <DTOClass> CreateNewDtoClass(DTOClass dto)
 {
     return(await repository.CreateAsync(dto));
 }
Exemple #8
0
        private List <DTOClass> setDto(Object obj)
        {
            if (obj.GetType().FullName != daoStruct.ClassName)
            {
                throw new Exception("类和配置的类名不一致");
            }
            List <DTOClass> dtolist = new List <DTOClass>();

            PropertyInfo[] props = obj.GetType().GetProperties();
            foreach (PropertyInfo pinfo in props)
            {
                DTOClass dto = new DTOClass();
                dto.name      = pinfo.Name.ToLower();
                dto.fieldtype = pinfo.PropertyType.Name.ToLower();
                dto.value     = pinfo.GetValue(obj, new object[] { });
                if (dto.value != null)
                {
                    switch (dto.fieldtype)
                    {
                    case "datetime":
                        long sdate = ((DateTime)dto.value).ToBinary();
                        if (sdate == 0)
                        {
                            dto.value = null;
                        }
                        else
                        {
                            dto.value = (DateTime)dto.value;
                        }
                        break;

                    case "boolean":
                        dto.value = (bool)dto.value;
                        break;

                    case "int32":
                        dto.value = (int)dto.value;
                        break;

                    case "int64":
                        dto.value = (long)dto.value;
                        break;

                    case "single":
                        dto.value = (float)dto.value;
                        break;

                    case "double":
                        dto.value = (double)dto.value;
                        break;

                    case "decimal":
                        dto.value = (decimal)dto.value;
                        break;

                    case "byte[]":
                        dto.value = (byte[])dto.value;
                        break;

                    default:
                        dto.value = (string)dto.value;
                        break;
                    }
                }
                dtolist.Add(dto);
            }
            return(dtolist);
        }
Exemple #9
0
        // public static List<DTOClass> listDto;

        public DtoList GetDtoData()
        {
            try
            {
                DALClass Obj     = new DALClass();
                DtoList  listDto = new DtoList();
                listDto.Emplist = new List <DTOClass>();
                EmpEntityList emp = Obj.GetAllDetails();
                foreach (var data in emp.Emplist)
                {
                    DTOClass dt = new DTOClass
                    {
                        Id           = data.Id,
                        Name         = data.Name,
                        DesgnationId = data.DesgnationId,
                        Designation  = data.Designation,
                        Gender       = data.Gender,
                        DepartmentId = data.DepartmentId,
                        Department   = data.Department,
                        Experience   = data.Experience,
                        Skills       = data.Skills,
                        EmailId      = data.EmailId,
                        ContactNo    = data.ContactNo,
                        SupervisorId = data.SupervisorId,
                        Supervisor   = data.Supervisor,
                        DateOfBirth  = data.DateOfBirth,
                        Address      = data.Address,
                        InsertedBy   = data.InsertedBy,
                        InsertedOn   = data.InsertedOn,
                        UpdatedBy    = data.UpdatedBy,
                        UpdatedOn    = data.UpdatedOn
                    };
                    listDto.Emplist.Add(dt);
                }

                listDto.DesnList = new List <LookupDTO>();
                foreach (var data in emp.DesnList)
                {
                    LookupDTO desgObj = new LookupDTO()
                    {
                        Id   = data.Id,
                        Name = data.Name
                    };
                    listDto.DesnList.Add(desgObj);
                }

                listDto.DeptList = new List <LookupDTO>();
                foreach (var data in emp.DeptList)
                {
                    LookupDTO deptObj = new LookupDTO()
                    {
                        Id   = data.Id,
                        Name = data.Name
                    };

                    listDto.DeptList.Add(deptObj);
                }
                listDto.SupervisorList = new List <DTOClass>();
                int c = emp.SupervisorList.Count();

                foreach (var data in emp.SupervisorList)
                {
                    DTOClass superObj = new DTOClass()
                    {
                        Id         = data.Id,
                        Supervisor = data.Supervisor
                    };
                    listDto.SupervisorList.Add(superObj);
                }
                return(listDto);
            }
            catch
            {
                return(null);
            }
        }