示例#1
0
 public MakeViewModel(MakeDto makeDto)
 {
     Id          = makeDto.Id;
     Name        = makeDto.Name;
     Description = makeDto.Description;
     Country     = makeDto.Country;
 }
示例#2
0
        public ActionResult Edit(MakeViewModel makeVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (MakeServiceReference.MakeClient service = new MakeServiceReference.MakeClient())
                    {
                        MakeDto makeDto = new MakeDto
                        {
                            Id          = makeVM.Id,
                            Name        = makeVM.Name,
                            Description = makeVM.Description,
                            Country     = makeVM.Country
                        };
                        service.PostMake(makeDto);
                    }

                    return(RedirectToAction("Index"));
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
        public bool Save(MakeDto makeDto)
        {
            Make make = new Make
            {
                Id          = makeDto.Id, // !NBBBB
                Name        = makeDto.Name,
                Description = makeDto.Description,
                Country     = makeDto.Country
            };

            try
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    if (makeDto.Id == 0)
                    {
                        unitOfWork.MakeRepository.Insert(make);
                    }
                    else
                    {
                        unitOfWork.MakeRepository.Update(make);
                    }

                    unitOfWork.Save();
                }
                return(true);
            }
            catch
            {
                Console.WriteLine(make);
                return(false);
            }
        }
示例#4
0
        public string PutMake(MakeDto makeDto)
        {
            if (!_context.Save(makeDto))
            {
                return("Make is not updated.");
            }

            return("Make is updated.");
        }
示例#5
0
        public string PostMake(MakeDto makeDto)
        {
            if (!_context.Save(makeDto))
            {
                return("Make is not inserted.");
            }

            return("Make is inserted.");
        }
        public MakeDto GetById(int id)
        {
            MakeDto makeDto = new MakeDto();

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                Make make = unitOfWork.MakeRepository.GetByID(id);
                if (make != null)
                {
                    makeDto = new MakeDto
                    {
                        Id          = make.Id,
                        Name        = make.Name,
                        Description = make.Description,
                        Country     = make.Country
                    };
                }
            }

            return(makeDto);
        }