Пример #1
0
        public async Task <Announcement> UpdateAnnouncement(AnnouncementUpdateDtos announcementUpdateDtos, IFormFile Imagefile, IFormFile DetailImageFile)
        {
            string ImageExtension = Path.GetExtension(Imagefile.FileName);
            string ImageName      = Guid.NewGuid() + ImageExtension;
            string Imagepath      = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/" + ImageName);

            using (var ImageStream = new FileStream(Imagepath, FileMode.Create))
            {
                await Imagefile.CopyToAsync(ImageStream);
            }

            //DetailImage

            string DetailImageExtension = Path.GetExtension(DetailImageFile.FileName);
            string DetailImageName      = Guid.NewGuid() + DetailImageExtension;
            string DetailImagePath      = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/" + DetailImageName);

            using (var DetailImageStream = new FileStream(DetailImagePath, FileMode.Create))
            {
                await DetailImageFile.CopyToAsync(DetailImageStream);
            }

            announcementUpdateDtos.BroadCastingStatus = "Aktif";
            announcementUpdateDtos.ImagePath          = ImageName;
            announcementUpdateDtos.DetailImagePath    = DetailImageName;
            announcementUpdateDtos.Date = DateTime.Now;


            await _announcementDal.UpdateAsync(_mapper.Map <Announcement>(announcementUpdateDtos));

            return(null);
        }
        public async Task <BasexResponse <Material> > UpdateAsync(Material material, string description)
        {
            try
            {
                var resultMaterial = await _materialDal.GetAsync(material.Id);

                resultMaterial.MaterialScale = material.MaterialScale;
                resultMaterial.Question      = material.Question;
                resultMaterial.Hint          = material.Hint;
                var resultAnnouncement = await _announcementDal.GetAsync(resultMaterial.AnnouncementId);

                resultAnnouncement.Description = description;

                var updatedMaterial = await _materialDal.UpdateAsync(resultMaterial, resultMaterial.Id);

                await _announcementDal.UpdateAsync(resultAnnouncement, resultAnnouncement.Id);

                await _unitOfWork.CompleteAsync();

                updatedMaterial.Announcement = null;//can't parse JSON
                return(new BasexResponse <Material>(updatedMaterial));
            }
            catch (Exception ex)
            {
                return(new BasexResponse <Material>(ex.Message));
            }
        }