Beispiel #1
0
 public BaseDto(IBaseDto item)
 {
     if (item != null)
     {
         Id      = item.Id;
         Name    = item.Name;
         Comment = item.Comment;
     }
 }
Beispiel #2
0
 public virtual void Copy(IBaseDto dto)
 {
     if (dto.GetType() == typeof(BaseFilmDto))
     {
         var that = (BaseFilmDto)dto;
         Title  = that.Title;
         Year   = that.Year;
         Length = that.Length;
     }
 }
Beispiel #3
0
        public ValidationResponse Validate(IValidator validator, IBaseDto dto)
        {
            var result   = validator.Validate(dto);
            var response = new ValidationResponse {
                IsValid = result.IsValid
            };

            result.Errors.ToList().ForEach(x => response.Errors.Add(x.ErrorMessage));
            return(response);
        }
Beispiel #4
0
 public virtual void Copy(IBaseDto dto)
 {
     if (dto.GetType() == typeof(BasePersonDto))
     {
         var that = (BasePersonDto)dto;
         FirstMidName = that.FirstMidName;
         LastName     = that.LastName;
         Birthdate    = that.Birthdate;
     }
 }
Beispiel #5
0
        public override Medium MapBack(IBaseDto dto)
        {
            var b = (BaseMediumDto)dto;
            var f = _filmRepository.GetByTitleAndYear(b.Title, b.Year).value;

            if (f == null)
            {
                throw new Exception("Unknown film");
            }
            return(new Medium(f.Id, b.MediumType, b.Location, b.HasGermanSubtitles));
        }
Beispiel #6
0
 public virtual void Copy(IBaseDto dto)
 {
     if (dto.GetType() == typeof(BaseFilmPersonDto))
     {
         var that = (BaseFilmPersonDto)dto;
         Title     = that.Title;
         Year      = that.Year;
         LastName  = that.LastName;
         Birthdate = that.Birthdate;
         Role      = that.Role;
     }
 }
Beispiel #7
0
 public virtual void Copy(IBaseDto dto)
 {
     if (dto.GetType() == typeof(BaseMediumDto))
     {
         var that = (BaseMediumDto)dto;
         Title              = that.Title;
         Year               = that.Year;
         MediumType         = that.MediumType;
         Location           = that.Location;
         HasGermanSubtitles = that.HasGermanSubtitles;
     }
 }
Beispiel #8
0
        public virtual bool Equals(IBaseDto dto)
        {
            var result = false;

            if (dto.GetType() == typeof(BasePersonDto))
            {
                var that = (BasePersonDto)dto;
                result = FirstMidName.Equals(that.FirstMidName) &&
                         LastName.Equals(that.LastName) &&
                         Birthdate.Equals(that.Birthdate);
            }
            return(result);
        }
Beispiel #9
0
        public virtual bool Equals(IBaseDto dto)
        {
            var result = false;

            if (dto.GetType() == typeof(BaseFilmDto))
            {
                var that = (BaseFilmDto)dto;
                result = Title.Equals(that.Title) &&
                         Year.Equals(that.Year) &&
                         Length.Equals(that.Length);
            }
            return(result);
        }
Beispiel #10
0
        public virtual bool Equals(IBaseDto dto)
        {
            var result = false;

            if (dto.GetType() == typeof(BaseMediumDto))
            {
                var that = (BaseMediumDto)dto;
                result = Title.Equals(that.Title) &&
                         Year.Equals(that.Year) &&
                         MediumType.Equals(that.MediumType) &&
                         Location.Equals(that.Location);
            }
            return(result);
        }
Beispiel #11
0
        public virtual bool Equals(IBaseDto dto)
        {
            var result = false;

            if (dto.GetType() == typeof(BaseFilmPersonDto))
            {
                var that = (BaseFilmPersonDto)dto;
                result = Title.Equals(that.Title) &&
                         Year.Equals(that.Year) &&
                         LastName.Equals(that.LastName) &&
                         Birthdate.Equals(that.Birthdate) &&
                         Role.Equals(that.Role);
            }
            return(result);
        }
Beispiel #12
0
        public override OperationStatus Update(IBaseDto dto)
        {
            var b       = (BaseFilmDto)dto;
            var results = _validator.Validate(b);

            IsValid = results.IsValid;
            if (!IsValid)
            {
                var vstatus = OperationStatus.BadRequest;
                vstatus.ReasonForFailure = "Invalid input";
                return(vstatus);
            }
            var filmToUpdate = _mapper.MapBack(b);

            return(_repository.Update(filmToUpdate));
        }
Beispiel #13
0
        public override FilmPerson MapBack(IBaseDto dto)
        {
            FilmPerson result = null;
            var        b      = (BaseFilmPersonDto)dto;
            var        f      = _filmRepository.GetByTitleAndYear(b.Title, b.Year).value;

            if (f == null)
            {
                throw new Exception("Unknown film");
            }
            var p = _personRepository.GetByLastNameAndBirthdate(b.LastName, b.Birthdate).value;

            if (f != null && p != null)
            {
                result = new FilmPerson(f.Id, p.Id, b.Role);
            }
            return(result);
        }
Beispiel #14
0
        public override OperationResult <IKeyedDto> Add(IBaseDto dto)
        {
            var b       = (BaseFilmDto)dto;
            var results = _validator.Validate(b);

            IsValid = results.IsValid;
            if (!IsValid)
            {
                var vstatus = OperationStatus.BadRequest;
                vstatus.ReasonForFailure = "Invalid input";
                return(new OperationResult <IKeyedDto>(vstatus));
            }
            var filmToAdd = _mapper.MapBack(b);

            var(status, value) = _repository.Add(filmToAdd);
            var val = RecoverKeyedEntity(value);

            return(new OperationResult <IKeyedDto>(status, val));
        }
Beispiel #15
0
        public IEntity MapToModel(IBaseDto entity)
        {
            if (entity == null)
            {
                throw new FormatException();
            }
            var dtoTypeName = entity.GetType().Name;

            switch (dtoTypeName)
            {
            case "GroupDto":
            {
                var groupDto = (GroupDto)entity;
                var id       = groupDto.Id;
                var a        = groupDto.GroupName;
                var x        = groupDto.MaxStudents;
                var s        = groupDto.StudyYear;
                return(new Group()
                    {
                        Id = groupDto.Id, GroupName = groupDto.GroupName, MaxStudents = groupDto.MaxStudents, StudyYear = groupDto.StudyYear
                    });
            }

            case "StudentDto":
            {
                var dtoEntity = (StudentDto)(IBaseDto)entity;
                return(new Student()
                    {
                        Id = dtoEntity.Id, FirstName = dtoEntity.FirstName, LastName = dtoEntity.LastName, PhoneNumber = dtoEntity.PhoneNumber, GroupId = dtoEntity.GroupId
                    });
            }

            case "SubjectDto":
            {
                var dtoEntity = (SubjectDto)(IBaseDto)entity;
                var enumInt   = (int)dtoEntity.FinalTestType;
                return(new Subject()
                    {
                        Id = dtoEntity.Id,
                        FinalTestType = (Model.FinalTestType)enumInt,
                        Hours = dtoEntity.Hours,
                        Name = dtoEntity.Name
                    });
            }

            case "SubjectInGroupDto":
            {
                var dtoEntity = (SubjectInGroupDto)(IBaseDto)entity;
                return(new SubjectInGroup()
                    {
                        Id = dtoEntity.Id,
                        GroupId = dtoEntity.GroupId,
                        SubjectId = dtoEntity.SubjectId
                    });
            }

            case "TeacherDto":
            {
                var dtoEntity = (TeacherDto)(IBaseDto)entity;
                return(new Teacher()
                    {
                        Id = dtoEntity.Id,
                        FirstName = dtoEntity.FirstName,
                        LastName = dtoEntity.LastName,
                        PhoneNumber = dtoEntity.PhoneNumber,
                        SubjectId = dtoEntity.SubjectId
                    });
            }

            case "TestDto":
            {
                var dtoEntity = (TestDto)(IBaseDto)entity;
                return(new Test()
                    {
                        Id = dtoEntity.Id,
                        Date = dtoEntity.Date,
                        Name = dtoEntity.Name,
                        Theme = dtoEntity.Theme,
                        TeacherId = dtoEntity.TeacherId
                    });
            }

            case "TestResultDto":
            {
                var dtoEntity = (TestResultDto)(IBaseDto)entity;
                return(new TestResult()
                    {
                        Id = dtoEntity.Id,
                        Mark = dtoEntity.Mark,
                        TestId = dtoEntity.TestId,
                        StudentId = dtoEntity.StudentId
                    });
            }

            default: throw new NotSupportedException();
            }
        }
Beispiel #16
0
 public static void ToEntity(this IBaseDto source)
 {
     Console.WriteLine("IBaseDto.ToEntity");
     //Do Stuff
 }
Beispiel #17
0
 public Check2BaseDto(IBaseDto item, int checkId)
 {
     IdCheck = checkId;
     IdBase  = item.Id;
     Comment = item.Comment;
 }
Beispiel #18
0
 public abstract T MapBack(IBaseDto dto);
Beispiel #19
0
        public override Film MapBack(IBaseDto dto)
        {
            var b = (BaseFilmDto)dto;

            return(new Film(b.Title, b.Year, b.Length));
        }
Beispiel #20
0
        public override Person MapBack(IBaseDto dto)
        {
            var b = (BasePersonDto)dto;

            return(new Person(b.LastName, b.Birthdate, b.FirstMidName));
        }
        public IEntity MapToModel(IBaseDto entity)
        {
            if (entity == null)
            {
                throw new FormatException();
            }
            var dtoTypeName = entity.GetType().Name;

            switch (dtoTypeName)
            {
            case "OrderDto":
            {
                var dtoEntity = (OrderDto)entity;
                return(new Order()
                    {
                        Id = dtoEntity.Id,
                        StartDate = dtoEntity.StartDate,
                        EndDate = dtoEntity.EndDate,
                        Sum = dtoEntity.Sum,
                        CustomerId = dtoEntity.CustomerId,
                        ManagerId = dtoEntity.ManagerId
                    });
            }

            case "CustomerDto":
            {
                var dtoEntity = (CustomerDto)(IBaseDto)entity;
                return(new Customer()
                    {
                        Id = dtoEntity.Id,
                        FirstName = dtoEntity.FirstName,
                        LastName = dtoEntity.LastName,
                        PhoneNumber = dtoEntity.PhoneNumber,
                        PassportSeries = dtoEntity.PassportSeries,
                        AccoutId = dtoEntity.AccoutId
                    });
            }

            case "CarDto":
            {
                var dtoEntity = (CarDto)(IBaseDto)entity;
                return(new Car()
                    {
                        Id = dtoEntity.Id,
                        Brand = dtoEntity.Brand,
                        Model = dtoEntity.Model,
                        SerialNumber = dtoEntity.SerialNumber,
                        Color = dtoEntity.Color,
                        Price = dtoEntity.Price,
                        ManufacturerId = dtoEntity.ManufacturerId
                    });
            }

            case "CarInOrderDto":
            {
                var dtoEntity = (CarInOrderDto)(IBaseDto)entity;
                return(new CarInOrder()
                    {
                        Id = dtoEntity.Id,
                        OrderId = dtoEntity.OrderId,
                        CarId = dtoEntity.CarId
                    });
            }

            case "ManagerDto":
            {
                var dtoEntity = (ManagerDto)(IBaseDto)entity;
                return(new Manager()
                    {
                        Id = dtoEntity.Id,
                        FirstName = dtoEntity.FirstName,
                        LastName = dtoEntity.LastName,
                        PhoneNumber = dtoEntity.PhoneNumber,
                        Salary = dtoEntity.Salary,
                        Position = dtoEntity.Position
                    });
            }

            case "ManufacturerDto":
            {
                var dtoEntity = (ManufacturerDto)(IBaseDto)entity;
                return(new Manufacturer()
                    {
                        Id = dtoEntity.Id,
                        Name = dtoEntity.Name,
                        OfficePhoneNumber = dtoEntity.OfficePhoneNumber,
                        Country = dtoEntity.Country
                    });
            }

            default: throw new NotSupportedException();
            }
        }
Beispiel #22
0
 private BaseDto _map(IBaseDto item)
 {
     return(new BaseDto(item));
 }
Beispiel #23
0
 public TableDto GetTable(IBaseDto table)
 {
     return(Tables.FirstOrDefault(t => t.MapId == table.Id));
 }