Beispiel #1
0
        public IActionResult Create([FromForm] CountryCreateModel entity)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext?.User?.Identity?.Name;
                if (!String.IsNullOrEmpty(currentUser))
                {
                    try
                    {
                        AuditedEntityMapper <CountryCreateModel> .FillCreateAuditedEntityFields(entity, currentUser);

                        bool statusResult = _countryService.Add(entity);
                        if (statusResult)
                        {
                            return(RedirectToAction(nameof(Index)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT));
                        }
                        else
                        {
                            return(RedirectToAction(nameof(Index)).WithError(LOCALIZATION_ERROR_DEFAULT));
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, ex.Message);
                        return(RedirectToAction(nameof(Index)).WithError(ex.Message));
                    }
                }
                else
                {
                    _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN);
                    return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN));
                }
            }
            return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE));
        }
Beispiel #2
0
        public IActionResult Create([FromForm] AdCreateModel entity)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext?.User?.Identity?.Name;
                if (!String.IsNullOrEmpty(currentUser))
                {
                    try
                    {
                        AuditedEntityMapper <AdCreateModel> .FillCreateAuditedEntityFields(entity, currentUser, CountryId);

                        entity.OwnerId = CurrentUserId;

                        #region File Map
                        //need to map files in controller because aspnet core assembly is present in project
                        string[] result;
                        if (!String.IsNullOrEmpty(entity.SerializedAdDetailsPictures))
                        {
                            result = Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>(entity.SerializedAdDetailsPictures);
                            entity.MainPictureFile = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(entity.MainPictureFile);
                            EntityFormMap(result, entity);
                        }
                        else
                        {
                            MapFiles(entity);
                        }
                        //
                        #endregion

                        bool statusResult = _adService.Add(entity);
                        if (statusResult)
                        {
                            return(RedirectToAction(nameof(Index)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT));
                        }
                        else
                        {
                            return(RedirectToAction(nameof(Index)).WithError(LOCALIZATION_ERROR_DEFAULT));
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, ex.Message);
                        return(RedirectToAction(nameof(Index)).WithError(ex.Message));
                    }
                }
                else
                {
                    _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN);
                    return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN));
                }
            }

            ViewBag.Cities     = _cityService.GetAllAsLookup(CountryId);
            ViewBag.Categories = _categoryService.GetAllAsLookup(CountryId);

            #region Preserve pictures if model validation fails
            string serializedString            = String.Empty;
            string mainPictureSerializedString = string.Empty;
            if (entity.Files != null && entity.Files.Count() > 0)
            {
                MapFiles(entity);
                serializedString            = Newtonsoft.Json.JsonConvert.SerializeObject(entity.FilesAsListOfByteArray);
                mainPictureSerializedString = Newtonsoft.Json.JsonConvert.SerializeObject(entity.FilesAsListOfByteArray.First());
            }
            if (!String.IsNullOrEmpty(entity.SerializedAdDetailsPictures))
            {
                string[] convertResult = Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>(entity.SerializedAdDetailsPictures);
                EntityFormMap(convertResult, entity);
                serializedString            = Newtonsoft.Json.JsonConvert.SerializeObject(entity.FilesAsListOfByteArray);
                mainPictureSerializedString = Newtonsoft.Json.JsonConvert.SerializeObject(entity.FilesAsListOfByteArray.First());
            }

            ViewBag.SerializedPictures          = serializedString;
            ViewBag.MainPictureSerializedString = mainPictureSerializedString;
            #endregion


            return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE));
        }
Beispiel #3
0
        public void Post([FromBody] CityCreateModel model)
        {
            AuditedEntityMapper <CityCreateModel> .FillCreateAuditedEntityFields(model, HttpContext?.User?.Identity?.Name);

            Ok(_cityService.Add(model));
        }