Exemplo n.º 1
0
        public async Task <IHttpActionResult> PutAuth(int id, Auth auth)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != auth.Id)
            {
                return(BadRequest());
            }

            db.Entry(auth).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,AddDate,ExpirationDate,UserIdVal,CategoryIdVal")] Ad ad, IFormFile image)
        {
            if (ModelState.IsValid)
            {
                using (var stream = new MemoryStream())
                {
                    await image.CopyToAsync(stream);

                    ad.Image = stream.ToArray();
                }

                ad.AddDate        = DateTime.Now;
                ad.ExpirationDate = ad.AddDate.AddDays(7);
                //ad.User = _context.Users.FirstOrDefault(e => e.Id == ad.UserIdVal);
                if (CurrentUser.User != null)
                {
                    ad.User = _context.Users.FirstOrDefault(e => e.Username == CurrentUser.User.Username);
                }
                ad.Category = _context.Categories.FirstOrDefault(e => e.Id == ad.CategoryIdVal);
                _context.Add(ad);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Categories"] = new SelectList(_context.Categories, "Id", "Id", ad.CategoryIdVal);
            //ViewData["Users"] = new SelectList(_context.Users, "Id", "Id", ad.UserIdVal);
            return(View(ad));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Id,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("ID,Name,Description,Price,CategoryId")] Advertisement advertisement)
        {
            if (ModelState.IsValid)
            {
                _context.Add(advertisement);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "ID", "Name", advertisement.CategoryId);
            return(View(advertisement));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Title,Description,AddDate,ExpirationDate")] Ad ad)
        {
            if (ModelState.IsValid)
            {
                ad.AddDate        = DateTime.Now;
                ad.ExpirationDate = ad.AddDate.AddDays(7);
                _context.Add(ad);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(ad));
        }
Exemplo n.º 6
0
        [ValidateAntiForgeryToken]                                  //"ID,UserId,City,Area,Address,Description,Studio,OneRoom,TwoRooms,ThreeRooms,Price,Contact,Date, Apartment
        public async Task <IActionResult> Create([Bind("ID,UserId,City,Area,Address,Description,Studio,OneRoom,TwoRooms,ThreeRooms,Price,Contact,Date")] Advertisement advertisement)
        {
            if (ModelState.IsValid)
            {
                advertisement.UserID = _userName;
                advertisement.Date   = DateTime.Now;
                _context.Add(advertisement);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["UserID"] = new SelectList(_context.Users, "ID", "ID", advertisement.UserID);
            return(View(advertisement));
        }
Exemplo n.º 7
0
        public async Task <Ad> CreateAd(string subject, string body, string email, double?price)
        {
            var ad = new Ad {
                Id         = Guid.NewGuid().ToString(),
                Subject    = subject,
                Body       = body,
                Email      = email,
                Price      = price,
                CreatedUtc = DateTime.UtcNow
            };

            _context.Ads.Add(ad);

            await _context.SaveChangesAsync();

            return(ad);
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("ID, City,Area,Address,Description,Studio,OneRoom,TwoRooms,ThreeRooms,Price,Contact,Date")] PutAdViewModel putad, IFormFile upload)
        {
            //if (ModelState.IsValid)
            //{
            //    _context.Add(putAdViewModel);
            //    await _context.SaveChangesAsync();
            //    return RedirectToAction("Index");
            //}
            //return View(putAdViewModel);


            if (ModelState.IsValid)
            {
                //if (upload != null && upload.Length > 0)
                //{
                //    //Models.File fileIn = new Models.File();
                //    Data.EfModels.UploadImage Imagein = new UploadImage();
                //    var fileName = ContentDispositionHeaderValue.Parse(upload.ContentDisposition).FileName.Trim('"');

                //    byte[] fileBytes = null;
                //    using (var fileStream = upload.OpenReadStream())
                //    using (var ms = new MemoryStream())
                //    {
                //        fileStream.CopyTo(ms);
                //        fileBytes = ms.ToArray();
                //        //string s = Convert.ToBase64String(fileBytes);
                //        // act on the Base64 data
                //    }


                //    Imagein.Imagename = fileName;
                //    Imagein.ContentType = upload.ContentType;
                //    Imagein.Content = fileBytes;
                //    _context.Add(Imagein);
                //    await _context.SaveChangesAsync();
                //    _context.Add(Imagein);
                //}

                _context.Add(putad);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            //ViewData["ID"] = new SelectList(_context.Users, "ID", "ID", advertisement.ID);
            return(View(putad));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Register([Bind("Id", "Username", "Password", "Email", "FirstName", "LastName", "TelephoneNumber")] User user)
        {
            if (ModelState.IsValid && user != null)
            {
                await _context.Users.AddAsync(user);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Exemplo n.º 10
0
        public async Task <IHttpActionResult> Config(DirectorySetup setup)
        {
            using (var context = new AdContext())
            {
                if (setup.Id == default(int))
                {
                    context.DirectorySetups.Add(setup);
                }
                else
                {
                    var data = context.DirectorySetups.Find(setup.Id);
                    if (data != null)
                    {
                        data.DomainName      = setup.DomainName;
                        data.IpAddress       = setup.IpAddress;
                        data.ServiceUserName = setup.ServiceUserName;
                        data.ServicePassword = setup.ServicePassword;
                    }
                }
                await context.SaveChangesAsync();

                return(Ok(new { state = true, message = "setup successful" }));
            }
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Create(int?id, [Bind("CommentID,UserId,AdvertisementID,DateOfComent,Text,Like,Dislike")] Comment comment)
        {
            //if (ModelState.IsValid)
            //{
            comment.UserId          = _userName;
            comment.AdvertisementID = (int)id;
            comment.DateOfComent    = DateTime.Now;
            comment.Like            = 0;
            comment.Dislike         = 0;
            _context.Add(comment);
            await _context.SaveChangesAsync();

            // return RedirectToAction("Index");
            //}
            var comments = _context.Comments;

            var model = new CommentViewModel(comments);

            return(View("~/Views/Comments/Index.cshtml", model));
        }
Exemplo n.º 12
0
 public async Task Update([FromBody] Ad ad)
 {
     _context.Update(ad);
     await _context.SaveChangesAsync();
 }