public bool CreateOrUpdate(CareerDTO career)
        {
            try
            {
                using (var ctx = new Utn_SysContext())
                {
                    var oCareer = ctx.Careers.AsNoTracking()
                                  .Where(c => c.Id == career.Id)
                                  .FirstOrDefault();

                    if (oCareer == null)
                    {
                        oCareer = new Careers();
                        ctx.Careers.Add(oCareer);
                    }
                    else
                    {
                        ctx.Careers.Attach(oCareer);
                    }
                    oCareer.Name    = career.Name;
                    oCareer.Deleted = false;

                    ctx.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #2
0
        public void EditCareer(CareerDTO careerDTO)
        {
            if (careerDTO == null)
            {
                throw new ArgumentNullException(nameof(careerDTO));
            }

            Career career = Database.Careers.Get(careerDTO.Id);

            if (career == null)
            {
                throw new ArgumentOutOfRangeException("Not found career");
            }

            if (Database.Rubrics.Get(careerDTO.RubricId) == null)
            {
                throw new ArgumentOutOfRangeException("Invalid argument rubricId");
            }

            career.Title        = careerDTO.Title;
            career.Company      = careerDTO.Company;
            career.City         = careerDTO.City;
            career.ContactName  = careerDTO.ContactName;
            career.ContactPhone = careerDTO.ContactPhone;
            career.Site         = careerDTO.Site;
            career.RubricId     = careerDTO.RubricId;
            career.Desctiption  = careerDTO.Desctiption;

            //career.UserId = careerDTO.UserId;

            Database.Careers.Update(career);
            Database.Save();
        }
 public bool Delete(CareerDTO career)
 {
     using (var ctx = new Utn_SysContext())
     {
         ctx.Careers.Remove(_mapper.Map <Careers>(career));
         ctx.SaveChanges();
         return(true);
     }
 }
예제 #4
0
        public Career ConvertToEF(CareerDTO DTO)
        {
            var EF = new Career()
            {
                CareerId   = DTO.CareerId,
                CareerName = DTO.CareerName
            };

            return(EF);
        }
예제 #5
0
        public void AddCareer(CareerDTO career)
        {
            AuthenticationService authentication = new AuthenticationService(services);
            string coach = HttpContext.Session.GetString("User_Login");

            if (authentication.IsCoach(coach))
            {
                CoachProfileService service = new CoachProfileService(services);
                service.AddCareer(career, coach);
            }
        }
예제 #6
0
        public void EditCareer_NullElement_ShouldThrowException()
        {
            //arrange
            var Career = new CareerDTO {
                Id = It.IsAny <int>(), ContactName = It.IsAny <string>(), ContactPhone = It.IsAny <string>()
            };

            careerRepository.Setup(x => x.Get(It.IsAny <int>())).Returns <Career>(null);

            //act & assert
            Assert.Throws <ArgumentOutOfRangeException>(() => carService.EditCareer(Career));
        }
예제 #7
0
        public void AddCareer(CareerDTO career, string login)
        {
            Career career1 = new Career
            {
                Company     = career.Company,
                Coach_Login = login,
                Description = career.Description,
                SYear       = career.SYear,
                FYear       = career.FYear,
                Position    = career.Position
            };

            db.Careers.Create(career1);
            db.Save();
        }
예제 #8
0
        public void RemoveCareer(CareerDTO careerDTO)
        {
            if (careerDTO == null)
            {
                throw new ArgumentNullException(nameof(careerDTO));
            }

            if (Database.Careers.Get(careerDTO.Id) == null)
            {
                throw new ArgumentOutOfRangeException("Not found career");
            }

            Database.Careers.Delete(careerDTO.Id);
            Database.Save();
        }
예제 #9
0
        public void CreateCareer_TryToCreateCareer_ShouldRepositoryCreateOnce()
        {
            var Career = new CareerDTO {
                Id = It.IsAny <int>()
            };

            uow.Setup(x => x.Rubrics.Get(It.IsAny <int>())).Returns(new Rubric()
            {
            });

            // act
            carService.CreateCareer(Career);

            //assert
            careerRepository.Verify(x => x.Create(It.IsAny <Career>()));
        }
예제 #10
0
        public void RemoveCareer_RemoveRepository_ShouldCallsOnce()
        {
            var Career = new CareerDTO {
                Id = It.IsAny <int>(), ContactName = It.IsAny <string>(), ContactPhone = It.IsAny <string>()
            };

            careerRepository.Setup(x => x.Get(It.IsAny <int>())).Returns(new Career {
                Id = It.IsAny <int>(), ContactName = It.IsAny <string>(), ContactPhone = It.IsAny <string>()
            });

            //act
            carService.RemoveCareer(Career);

            //assert
            careerRepository.Verify(x => x.Delete(It.IsAny <int>()));
        }
예제 #11
0
        public void EditCareer_EditCareer_ShoudRepositoryEditOnce()
        { //arrange
            var Career = new CareerDTO {
                Id = It.IsAny <int>(), ContactName = It.IsAny <string>(), ContactPhone = It.IsAny <string>()
            };

            careerRepository.Setup(x => x.Get(It.IsAny <int>())).Returns(new Career {
                Id = It.IsAny <int>(), ContactPhone = It.IsAny <string>()
            });
            careerRepository.Setup(x => x.Get(It.IsAny <int>())).Returns(new Career());
            uow.Setup(x => x.Rubrics.Get(It.IsAny <int>())).Returns(new Rubric());


            // act
            carService.EditCareer(Career);

            //assert
            careerRepository.Verify(x => x.Update(It.IsAny <Career>()));
        }
예제 #12
0
        public void CreateCareer(CareerDTO careerDTO)
        {
            if (careerDTO == null)
            {
                throw new ArgumentNullException(nameof(careerDTO));
            }

            if (careerDTO.Id != 0 && Database.Careers.Get(careerDTO.Id) != null)
            {
                throw new ArgumentOutOfRangeException("Found duplicate id career");
            }

            if (Database.Rubrics.Get(careerDTO.RubricId) == null)
            {
                throw new ArgumentOutOfRangeException("Invalid argument rubricId");
            }

            Database.Careers.Create(Mapper.Map <CareerDTO, Career>(careerDTO));
            Database.Save();
        }
예제 #13
0
        public IHttpActionResult Add(CareerViewModel careerView)
        {
            CareerDTO careerDTO = Mapper.Map <CareerViewModel, CareerDTO>(careerView);

            careerDTO.UserId = userService.GetUsers().Where(x => x.UserName == User.Identity.Name).FirstOrDefault().Id;

            try
            {
                careerService.CreateCareer(careerDTO);
            }
            catch (ArgumentNullException)
            {
                return(BadRequest());
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return(BadRequest(ex.ParamName));
            }

            return(Ok());
        }
예제 #14
0
 public bool Delete(CareerDTO student)
 {
     return(studentRepo.Delete(student));
 }
예제 #15
0
 public bool CreateOrUpdate(CareerDTO student)
 {
     return(studentRepo.CreateOrUpdate(student));
 }
예제 #16
0
        public CareerDTO ConvertToDTO(Career EF)
        {
            var DTO = new CareerDTO()
            {
                CareerId   = EF.CareerId,
                CareerName = EF.CareerName
            };

            switch (DTO.CareerId)
            {
            case (int)Common.Enum.EnumCareer.BanHangTiepThi:
                DTO.Icon = "la la-tag";
                break;

            case (int)Common.Enum.EnumCareer.HangTieuDung:
                DTO.Icon = "la la-cart-plus";
                break;

            case (int)Common.Enum.EnumCareer.KyThuat:
                DTO.Icon = "la la-gears";
                break;

            case (int)Common.Enum.EnumCareer.DichVu:
                DTO.Icon = "la la-globe";
                break;

            case (int)Common.Enum.EnumCareer.MayTinhIT:
                DTO.Icon = "la la-desktop";
                break;

            case (int)Common.Enum.EnumCareer.SucKhoe:
                DTO.Icon = "la la-user-md";
                break;

            case (int)Common.Enum.EnumCareer.SanXuat:
                DTO.Icon = "la la-industry";
                break;

            case (int)Common.Enum.EnumCareer.HanhChinhNhanSu:
                DTO.Icon = "la la-users";
                break;

            case (int)Common.Enum.EnumCareer.KeToanTaiChinh:
                DTO.Icon = "la la-money";
                break;

            case (int)Common.Enum.EnumCareer.TruyenThongMedia:
                DTO.Icon = "la la-bullhorn";
                break;

            case (int)Common.Enum.EnumCareer.XayDung:
                DTO.Icon = "la la-building";
                break;

            case (int)Common.Enum.EnumCareer.GiaoDucDaoTao:
                DTO.Icon = "la la-graduation-cap";
                break;

            case (int)Common.Enum.EnumCareer.KhoaHoc:
                DTO.Icon = "la la-flask";
                break;

            case (int)Common.Enum.EnumCareer.KhachSanDuLich:
                DTO.Icon = "la la-globe";
                break;

            default:
                DTO.Icon = "la la-bars";
                break;
            }
            return(DTO);
        }