コード例 #1
0
        public async Task <OnSaleProperty> AddOnSaleProperty(OnSaleProperty property)
        {
            if (property != null)
            {
                property.IsActive = true;

                IFormFile[] files     = new IFormFile[] { property.imageFile1, property.imageFile2, property.imageFile3, property.imageFile4 };
                string[]    fileLinks = new string[] { property.ImageLink1, property.ImageLink2, property.ImageLink3, property.ImageLink4 };

                for (int i = 0; i < files.Length; i++)
                {
                    if (files[i] == null)
                    {
                        fileLinks[i] = "#";
                    }
                    else
                    {
                        fileLinks[i] = GetFileUploadBlobReturnsLink(files[i]);
                    }
                }
                property.ImageLink1 = fileLinks[0];
                property.ImageLink2 = fileLinks[1];
                property.ImageLink3 = fileLinks[2];
                property.ImageLink4 = fileLinks[3];


                _db.OnSaleProperties.Add(property);
                await _db.SaveChangesAsync();

                return(property);
            }

            return(null);
        }
コード例 #2
0
        public async Task <OnSaleProperty> EditOnSaleProperty(int id, OnSaleProperty property)
        {
            OnSaleProperty onSale = null;

            onSale    = _db.OnSaleProperties.AsNoTracking().FirstOrDefault(m => m.Id == id);
            onSale    = property;
            onSale.Id = id;

            _db.OnSaleProperties.Update(onSale);
            await _db.SaveChangesAsync();

            return(onSale);
        }
コード例 #3
0
        //  [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
        public async Task <IActionResult> AddOnSaleProperty([FromForm] OnSaleProperty property)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _manager.AddOnSaleProperty(property);

            if (result != null)
            {
                return(Ok(result));
            }

            return(BadRequest());
        }
コード例 #4
0
        //  [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
        public async Task <IActionResult> EditOnSaleProperty([FromRoute] int id, [FromBody] OnSaleProperty property)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _manager.EditOnSaleProperty(id, property);

            if (result != null)
            {
                return(Ok(result));
            }

            return(BadRequest());
        }