Пример #1
0
        public IActionResult GetByUserId(int id)
        {
            ShopServices shs   = new ShopServices(_config, _logger);
            var          model = shs.GetByUserId(id);

            return(Ok(new ResponseResult(200, StatusMessage.Completed.ToString(), "", model)));
        }
Пример #2
0
        public async Task <IActionResult> AddOrUpdate(int?id, string name, string address, string phoneNo, string latitude, string longitude, bool?isActive, string updatedBy, IFormFile file)
        {
            _logger.LogInformation("Shop/AddOrUpdate");
            _logger.LogInformation("id: {0} name: {1} file: {2} type: {3} len: {4}", id, name, file.FileName, file.ContentType, file.Length);

            int userId = !id.HasValue ? 0 : id.Value;

            string       imageUrl    = "";
            ShopServices shs         = new ShopServices(_config, _logger);
            string       lat         = latitude;
            string       lng         = longitude;
            string       createdBy   = updatedBy;
            DateTime?    createdDate = DateTime.Now;

            Shop local = shs.GetByUserId(userId);

            if (local != null)
            {
                _logger.LogInformation("local.userid=" + local.UserId);
                imageUrl = await FileHelpers.FileUpload(userId, file) ?? local.ImageUrl;

                lat         = !string.IsNullOrEmpty(latitude) ? latitude : local.Latitude;
                lng         = !string.IsNullOrEmpty(longitude) ? longitude : local.Longitude;
                createdBy   = local.CreatedBy;
                createdDate = local.CreatedDate;
            }
            else
            {
                _logger.LogInformation("New");
                imageUrl = await FileHelpers.FileUpload(userId, file);
            }

            Shop model = new Shop()
            {
                UserId      = userId,
                Name        = name,
                Address     = address,
                PhoneNo     = phoneNo,
                ImageUrl    = imageUrl,
                Latitude    = lat,
                Longitude   = lng,
                IsActive    = isActive == null ? true : isActive,
                IsDelete    = false,
                UpdatedDate = DateTime.Now,
                UpdatedBy   = updatedBy,
                CreatedDate = createdDate,
                CreatedBy   = createdBy
            };

            shs.AddOrUpdate(model);

            return(Ok(new ResponseResult(200, StatusMessage.Completed.ToString(), "", model)));
        }