Ejemplo n.º 1
0
 public IActionResult AddLocker([FromBody] Content _cont)
 {
     if (_contentRepo.AddContent(_cont))
     {
         return(Ok(_cont.Id_content));
     }
     return(NotFound());
 }
Ejemplo n.º 2
0
        public IActionResult AddContent([FromBody] Content _cont)
        {
            TimeZoneInfo zone     = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
            DateTime     dateTime = TimeZoneInfo.ConvertTime(DateTime.Now, zone);

            //if adding content success
            if (_contentRepo.AddContent(_cont))
            {
                Log.Information("Add content {id} OK. {DateTime}.", _cont.Id_content, dateTime);
                return(Ok(_cont.Id_content));
            }
            //if adding content fail
            Log.Information("Cannot Add content {id}. {DateTime}.", _cont.Id_content, dateTime);
            return(NotFound());
        }
Ejemplo n.º 3
0
        public JsonResult Add()
        {
            ContentAddViewModel vm = new ContentAddViewModel();

            vm.Status = "error";
            // vm.WebRootPath = _environment.WebRootPath;
            string title = RequestUtils.GetFormText(Request, "title");
            string text  = RequestUtils.GetFormText(Request, "text");
            string token = RequestUtils.GetFormText(Request, "token");

            // Валидация.
            if (string.IsNullOrEmpty(title))
            {
                vm.ErrorTitle = _localizationService.GetValue("Input post title");
            }
            if (string.IsNullOrEmpty(text))
            {
                vm.ErrorText = _localizationService.GetValue("Input post text");
            }
            if (!string.IsNullOrEmpty(token))
            {
                _profileService.GetCurrentAccountByToken(token);
            }

            /* var account = _accountRepository.GetAccountByEmail(User.Identity.Name);
             * if (account == null)
             * {
             *   //return 404;
             *   vm.Result = "account == null";
             * }*/
            if (string.IsNullOrEmpty(vm.ErrorTitle) && string.IsNullOrEmpty(vm.ErrorText) && _profileService.CurrentProfile != null)
            {
                var content = new Content
                {
                    ProfileID   = _profileService.CurrentProfile.ID,// Указываем профиль из запроса
                    Title       = title,
                    Text        = text,
                    CreateDate  = DateTime.Now,
                    UpdateDate  = DateTime.Now,
                    PublishDate = DateTime.Now
                };
                content.ID = _contentRepository.AddContent(content);

                vm.Status = "success";
                vm.Title  = content.Title;
                vm.Text   = content.Text;
                // Формирование даты для вывода.
                vm.Date = content.CreateDate.ToString("dd MMMM yyyy") + " в " + content.CreateDate.ToString("HH:mm");
                string image = "";
                var    files = _fileStorageService.SaveFiles(_environment.WebRootPath, Request.Form.Files, content.ID, "content");
                if (files != null && files.Count > 0)
                {
                    image         = files[0].Filename;
                    content.Image = image;
                    _contentRepository.UpdateContentImage(content);
                }
                // TODO для отрисовки ссылка на картинку
                vm.ImageLink = LinkBuilder.Image(image, true);
            }
            else
            {
            }

            return(Json(vm));
        }