public async Task <IActionResult> InsertAsync(string NameFaculty, [FromBody] DepartmentMeta departmentMeta)
        {
            var result = await _department.InsertAsync(NameFaculty, departmentMeta);

            return(Ok(result));
        }
        public async Task <IActionResult> UpdateAsync(string idDepartment, DepartmentMeta department)
        {
            var result = await _department.UpdateAsync(idDepartment, department);

            return(Ok(result));
        }
Ejemplo n.º 3
0
        public async Task <ActionResultReponese <string> > UpdateAsync(string IdDepartment, DepartmentMeta department)
        {
            var idfaculty = await _facultyRepository.CheckExitsIdFacult(department.IdFaculty);

            if (!idfaculty)
            {
                return(new ActionResultReponese <string>(-21, "khoa khong ton tai", "Faculty"));
            }
            var _department = new Department
            {
                IdDepartment   = IdDepartment?.Trim(),
                NameDepartment = department.NameDepartment?.Trim(),
                Office         = department.Office?.Trim(),
                Addres         = department.Addres?.Trim(),
                Email          = department.Email?.Trim(),
                PhoneNumber    = department.PhoneNumber?.Trim(),
                IdFaculty      = department.IdFaculty?.Trim(),
                LastUpdate     = DateTime.Now,
            };
            var Result = await _departmentRepository.UpdateAsync(_department);

            if (Result > 0)
            {
                return(new ActionResultReponese <string>(Result, "Update thanh cong", "Department", null));
            }
            return(new ActionResultReponese <string>(Result, "Update that bai", "Department", null));
        }
Ejemplo n.º 4
0
        public async Task <ActionResultReponese <string> > InsertAsync(string NameFaculty, DepartmentMeta department)
        {
            var idfaculty = await _facultyRepository.CheckExitsFacult(NameFaculty);

            if (!idfaculty)
            {
                return(new ActionResultReponese <string>(-21, "khoa khong ton tai", "Faculty"));
            }
            var namedeartment = await _departmentRepository.CheckExitsDepartment(department.NameDepartment);

            if (namedeartment)
            {
                return(new ActionResultReponese <string>(-22, "Bo mon da ton tai", "Department"));
            }
            var _department = new Department
            {
                IdDepartment   = Guid.NewGuid().ToString(),
                NameDepartment = department.NameDepartment?.Trim(),
                Office         = department.Office?.Trim(),
                Addres         = department.Addres?.Trim(),
                Email          = department.Email?.Trim(),
                PhoneNumber    = department.PhoneNumber?.Trim(),
                IdFaculty      = department.IdFaculty?.Trim(),
                CreateDate     = DateTime.Now,
                LastUpdate     = null,
                IsActive       = true,
                IsDelete       = false,
                DeleteTime     = null
            };
            var Result = await _departmentRepository.InsertAsync(_department);

            if (Result >= 0)
            {
                return(new ActionResultReponese <string>(Result, "them thanh cong", "Department", null));
            }
            return(new ActionResultReponese <string>(Result, "them that bai", "Department", null));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// chu y duong dan lay file excel la lay tu upload cua API upFile
        ///
        /// </summary>
        /// <param name="NameFaculty"></param>
        /// <returns></returns>
        public async Task <ActionResultReponese <string> > InsertListExcelAsync(string NameFaculty)
        {
            List <DepartmentMeta> departmentlist = new List <DepartmentMeta>();

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            using (var pakage = new ExcelPackage(new FileInfo("Exceltest\\ExceltestDepartment.xlsx")))
            {
                ExcelWorksheet worsheet = pakage.Workbook.Worksheets[0];
                for (int i = worsheet.Dimension.Start.Row + 1; i <= worsheet.Dimension.End.Row; i++)
                {
                    //StudentTest st1 = new StudentTest();
                    int            j              = 1;
                    string         Email          = worsheet.Cells[i, j++].Value.ToString();
                    string         adress         = worsheet.Cells[i, j++].Value.ToString();
                    string         namedepartment = worsheet.Cells[i, j++].Value.ToString();
                    string         office         = worsheet.Cells[i, j++].Value.ToString();
                    string         phonnumber     = worsheet.Cells[i, j++].Value.ToString();
                    string         idfacultymeta  = worsheet.Cells[i, j++].Value.ToString();
                    DepartmentMeta _depart        = new DepartmentMeta()
                    {
                        Email          = Email,
                        Addres         = adress,
                        NameDepartment = namedepartment,
                        Office         = office,
                        PhoneNumber    = phonnumber,
                        IdFaculty      = idfacultymeta,
                    };
                    departmentlist.Add(_depart);
                }
                int dem = 0;
                foreach (var item in departmentlist)
                {
                    var idfaculty = await _facultyRepository.CheckExitsFacult(NameFaculty);

                    if (!idfaculty)
                    {
                        return(new ActionResultReponese <string>(-21, "khoa khong ton tai", "Faculty"));
                    }

                    var namedeartment = await _departmentRepository.CheckExitsDepartment(item.NameDepartment);

                    if (namedeartment)
                    {
                        return(new ActionResultReponese <string>(-22, "Bo mon da ton tai", "Department"));
                    }
                    var _department = new Department
                    {
                        IdDepartment   = Guid.NewGuid().ToString(),
                        NameDepartment = item.NameDepartment?.Trim(),
                        Office         = item.Office?.Trim(),
                        Addres         = item.Addres?.Trim(),
                        Email          = item.Email?.Trim(),
                        PhoneNumber    = item.PhoneNumber?.Trim(),
                        IdFaculty      = item.IdFaculty?.Trim(),
                        CreateDate     = DateTime.Now,
                        LastUpdate     = null,
                        IsActive       = true,
                        IsDelete       = false,
                        DeleteTime     = null
                    };
                    var Result = await _departmentRepository.InsertAsync(_department);

                    if (Result > 0)
                    {
                        dem++;
                    }
                }
                if (dem > 0)
                {
                    return(new ActionResultReponese <string>(-5, "them thanh cong", "Department", null));
                }
                return(new ActionResultReponese <string>(dem, "them that bai", "Department", null));
            }
        }
Ejemplo n.º 6
0
        public async Task <ActionResultReponese <string> > UpdateAsync(string IdDepartment, DepartmentMeta department)
        {
            var _bomon = new Department
            {
                //  id = Guid.NewGuid().ToString(),
                NameDepartment = department.NameDepartment?.Trim(),
                IdFaculty      = department.IdFaculty?.Trim(),
                IsActive       = true,
                IsDelete       = false,
                LastUpdate     = DateTime.Now,
            };
            var Result = await _departmentRepository.UpdateAsync(IdDepartment, _bomon);

            if (Result > 0)
            {
                return(new ActionResultReponese <string>(Result, "Update thanh cong", "Department", null));
            }
            return(new ActionResultReponese <string>(Result, "Update that bai", "Department", null));
        }
Ejemplo n.º 7
0
        public async Task <ActionResultReponese <string> > InsertAsync(string IdFaculty, DepartmentMeta bomonMeta)
        {
            var isFaculty = await _facultyRepository.CheckExitsFacult(IdFaculty);

            if (!isFaculty)
            {
                return(new ActionResultReponese <string>(-21, "IdFaculty not found", "Faculty", null));
            }
            var _bomon = new Department
            {
                //  id = Guid.NewGuid().ToString(),
                // IdDepartment = bomonMeta.IdDepartment?.Trim(),
                NameDepartment = bomonMeta.NameDepartment?.Trim(),
                IdFaculty      = IdFaculty?.Trim(),
                CreateDate     = DateTime.Now,
                IsActive       = true,
                IsDelete       = false
            };
            var Result = await _departmentRepository.InsertAsync(_bomon);

            if (Result >= 0)
            {
                return(new ActionResultReponese <string>(Result, "thanh cong", "Department", null));
            }
            return(new ActionResultReponese <string>(Result, "that bai", "Department", null));
        }