예제 #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));
        }
        public IActionResult Create([FromForm] LocalizationCreateModel entity)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    AuditedEntityMapper <LocalizationCreateModel> .FillCountryEntityField(entity, CountryId);

                    bool statusResult = _localizationService.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));
                }
            }

            ViewBag.Languages = _languageService.GetAllAsLookup(CountryId);
            return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE));
        }
예제 #3
0
        public IActionResult Create([FromForm] LanguageCreateModel entity)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    AuditedEntityMapper <LanguageCreateModel> .FillCountryEntityField(entity, CountryId);

                    bool statusResult = _languageService.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));
                }
            }
            return(View(entity));
        }
예제 #4
0
        public IActionResult Edit([FromForm] CountryEditModel entity)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext?.User?.Identity?.Name;
                if (!String.IsNullOrEmpty(currentUser))
                {
                    AuditedEntityMapper <CountryEditModel> .FillModifyAuditedEntityFields(entity, currentUser);

                    try
                    {
                        _countryService.Update(entity);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!CountryExists(entity.ID))
                        {
                            _logger.LogError(LOCALIZATION_ERROR_NOT_FOUND);
                            return(NotFound().WithError(LOCALIZATION_ERROR_NOT_FOUND));
                        }
                        else
                        {
                            _logger.LogError(LOCALIZATION_ERROR_CONCURENT_EDIT);
                            return(NotFound().WithError(LOCALIZATION_ERROR_CONCURENT_EDIT));
                        }
                    }

                    return(RedirectToAction(nameof(Details), new { id = entity.ID }).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT));
                }
                else
                {
                    _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN);
                    return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN));
                }
            }
            return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE));
        }
        public IActionResult Edit([FromBody] CategoryEditModel entity)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext?.User?.Identity?.Name;
                if (!String.IsNullOrEmpty(currentUser))
                {
                    AuditedEntityMapper <CategoryEditModel> .FillModifyAuditedEntityFields(entity, currentUser);

                    try
                    {
                        _categoryService.Update(entity);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!CategoryExists(entity.ID))
                        {
                            _logger.LogError(LOCALIZATION_ERROR_NOT_FOUND);
                            return(NotFound().WithError(LOCALIZATION_ERROR_NOT_FOUND));
                        }
                        else
                        {
                            _logger.LogError(LOCALIZATION_ERROR_CONCURENT_EDIT);
                            return(NotFound().WithError(LOCALIZATION_ERROR_CONCURENT_EDIT));
                        }
                    }
                    return(Ok().WithSuccess(LOCALIZATION_SUCCESS_DEFAULT));
                }
                else
                {
                    _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN);
                    return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN));
                }
            }
            return(View(entity));
        }
예제 #6
0
        public IActionResult Edit([FromForm] AdEditModel entity)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext?.User?.Identity?.Name;
                if (!String.IsNullOrEmpty(currentUser))
                {
                    AuditedEntityMapper <AdEditModel> .FillModifyAuditedEntityFields(entity, currentUser);

                    entity.OwnerId = CurrentUserId;

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

                    try
                    {
                        _adService.Update(entity);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!AdExists(entity.ID))
                        {
                            _logger.LogError(LOCALIZATION_ERROR_NOT_FOUND);
                            return(NotFound().WithError(LOCALIZATION_ERROR_NOT_FOUND));
                        }
                        else
                        {
                            _logger.LogError(LOCALIZATION_ERROR_CONCURENT_EDIT);
                            return(NotFound().WithError(LOCALIZATION_ERROR_CONCURENT_EDIT));
                        }
                    }

                    return(RedirectToAction(nameof(MyAds)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT));
                }
                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));
        }
예제 #7
0
        public void Put([FromBody] CityEditModel model)
        {
            AuditedEntityMapper <CityEditModel> .FillModifyAuditedEntityFields(model, HttpContext?.User?.Identity?.Name);

            Ok(_cityService.Update(model));
        }
예제 #8
0
        public void Post([FromBody] CityCreateModel model)
        {
            AuditedEntityMapper <CityCreateModel> .FillCreateAuditedEntityFields(model, HttpContext?.User?.Identity?.Name);

            Ok(_cityService.Add(model));
        }