示例#1
0
        public async Task <ActionResult <ServiceCM> > CreateService([FromForm] ServiceCM serviceModel)
        {
            //TODO: Implements AccountService.GetById(int id) does not exist, return BadRequest()
            //TODO: Implements ServiceTypeId.GetById(int id) does not exist, return BadRequest()
            //TODO: Implements GaleryId.GetById(int id) does not exist, return BadRequest()


            DateTime crtDate = DateTime.Now;
            DateTime updDate = DateTime.Now;
            string   status  = Constants.Status.ACTIVE;

            // Initialize gallery
            GalleryCM galleryCM = new GalleryCM();

            galleryCM.Name        = "Hình " + serviceModel.ServiceName.ToLower();
            galleryCM.Description = "Hình " + serviceModel.ServiceName.ToLower();;

            // Add new gallery
            Gallery gallery    = _mapper.Map <Gallery>(galleryCM);
            Gallery crtGallery = await _galleryService.AddAsync(gallery);

            await _galleryService.Save();

            ImageCM imageCM = new ImageCM();

            imageCM.Description = "Hình " + serviceModel.ServiceName;
            imageCM.GalleryId   = crtGallery.Id;
            imageCM.ImageUrl    = await _uploadFileService.UploadFile("123456798", serviceModel.File, "service", "service-detail");

            Image image = _mapper.Map <Image>(imageCM);
            await _imageService.AddAsync(image);

            Service crtService = _mapper.Map <Service>(serviceModel);

            try
            {
                crtService.CreatedDate   = crtDate;
                crtService.UpdatedDate   = updDate;
                crtService.Status        = status;
                crtService.AccountId     = serviceModel.AccountId;
                crtService.ServiceTypeId = serviceModel.ServiceTypeId;
                crtService.GalleryId     = crtGallery.Id;

                await _service.AddAsync(crtService);

                await _service.Save();
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(CreatedAtAction("GetServiceById", new { id = crtService.Id }, crtService));
        }
示例#2
0
        public async Task <ActionResult <FeedBackCM> > CreateFeedback([FromForm] FeedBackCM feedbackModel)
        {
            //TODO: Implements BookingDetail.GetById(int id) does not exist, return BadRequest()
            //TODO: Implements GaleryId.GetById(int id) does not exist, return BadRequest()

            if (feedbackModel.File != null)
            {
                GalleryCM galleryCM = new GalleryCM();
                galleryCM.Name        = "Hình feedback cho dịch vụ trong đơn " + feedbackModel.BookingDetailId;
                galleryCM.Description = "Hình feedback cho dịch vụ trong đơn " + feedbackModel.BookingDetailId;

                Gallery gallery    = _mapper.Map <Gallery>(galleryCM);
                Gallery crtGallery = await _galleryService.AddAsync(gallery);

                await _galleryService.Save();

                feedbackModel.GalleryId = crtGallery.Id;

                ImageCM imageCM = new ImageCM();
                imageCM.Description = "Hình feedback trong đơn " + feedbackModel.BookingDetailId;
                imageCM.GalleryId   = crtGallery.Id;
                imageCM.ImageUrl    = await _uploadFileService.UploadFile("123456798", feedbackModel.File, "service", "service-detail");

                Image image = _mapper.Map <Image>(imageCM);
                await _imageService.AddAsync(image);
            }

            FeedBack crtFeedback = _mapper.Map <FeedBack>(feedbackModel);

            try
            {
                crtFeedback.CreateDate = DateTime.Now;

                await _service.AddAsync(crtFeedback);

                await _service.Save();
            }
            catch (Exception e)
            {
                //return StatusCode(StatusCodes.Status500InternalServerError);
                NotFound(e);
            }

            return(CreatedAtAction("GetFeedBackById", new { id = crtFeedback.Id }, crtFeedback));
        }
        public async Task <IActionResult> Add(AddGalleryViewModel model)
        {
            if (!await articleService.ExistsAsync(model.ArticleId))
            {
                TempData.AddErrorMessage("Invalid article.");
                return(RedirectToAction("Index", "Home"));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var galleryId = await galleryService.AddAsync(model.Name, model.PhotographerName, model.ArticleId);

            if (galleryId == 0)
            {
                TempData.AddErrorMessage("Save failed.");
                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction(nameof(AddPictures), galleryId));
        }
示例#4
0
        public async Task <ActionResult <GalleryCM> > CreateGallery([FromBody] GalleryCM galleryModel)
        {
            /*DateTime crtDate = DateTime.Now;
            *  DateTime updDate = DateTime.Now;*/

            Gallery crtGallery = _mapper.Map <Gallery>(galleryModel);

            try
            {
                /*crtService.CreatedDate = crtDate;
                *  crtService.UpdatedDate = updDate;*/
                /*crtGallery.DefaultImageId = defaultImageId;*/

                await _service.AddAsync(crtGallery);

                await _service.Save();
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }

            return(CreatedAtAction("GetGalleryById", new { id = crtGallery.Id }, crtGallery));
        }