예제 #1
0
        public async Task <IActionResult> PutSettings(Guid id, Settings settings)
        {
            if (id != settings.Id)
            {
                return(BadRequest());
            }

            _context.Entry(settings).State = EntityState.Modified;

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

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> PutNotification(Guid id, Notification notification)
        {
            if (id != notification.Id)
            {
                return(BadRequest());
            }

            _context.Entry(notification).State = EntityState.Modified;

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

            return(NoContent());
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Id,Password,Email")] Users users)
        {
            if (ModelState.IsValid)
            {
                users.Id = Guid.NewGuid();
                _context.Add(users);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(users));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("Id,ProjectKey,VersionNumber,UpdateRequired")] Settings settings)
        {
            if (ModelState.IsValid)
            {
                settings.Id = Guid.NewGuid();
                _context.Add(settings);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(settings));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("Id,Token,Device,CreateDate")] NotificationToken notificationToken)
        {
            if (ModelState.IsValid)
            {
                notificationToken.Id = Guid.NewGuid();
                _context.Add(notificationToken);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(notificationToken));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("Id,DrawersId,Rank")] Cartoon cartoon)
        {
            if (ModelState.IsValid)
            {
                cartoon.Id = Guid.NewGuid();
                _context.Add(cartoon);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DrawersId"] = new SelectList(_context.Drawer, "Id", "Name", cartoon.DrawersId);
            return(View(cartoon));
        }
        public async Task <IActionResult> Create([Bind("Id,CartoonId,UniqUserKey")] CartoonLikes cartoonLikes)
        {
            if (ModelState.IsValid)
            {
                cartoonLikes.Id = Guid.NewGuid();
                _context.Add(cartoonLikes);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CartoonId"] = new SelectList(_context.Cartoon, "Id", "Id", cartoonLikes.CartoonId);
            return(View(cartoonLikes));
        }
예제 #8
0
        public async Task <ActionResult> BulkCartoonInsert(Guid DrawerId, List <IFormFile> CartoonImages)
        {
            try
            {
                int maxRank = await _context.Cartoon.MaxAsync(x => x.Rank);

                foreach (IFormFile file in CartoonImages)
                {
                    maxRank++;
                    var    guid          = Guid.NewGuid();
                    string directoryPath = $"{_env.WebRootPath}/Image/{guid}/";
                    if (!Directory.Exists(directoryPath))
                    {
                        Directory.CreateDirectory(directoryPath);
                    }

                    using (var stream = new FileStream($"{directoryPath}/{file.FileName}", FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }

                    string imageSrc = "/Image/" + guid + "/" + file.FileName;

                    var cartoon = new Cartoon()
                    {
                        DrawersId = DrawerId,
                        Id        = Guid.NewGuid(),
                        Rank      = maxRank
                    };
                    await _context.Cartoon.AddAsync(cartoon);

                    await _context.SaveChangesAsync();

                    var cartoonImage = new CartoonImages()
                    {
                        Id        = Guid.NewGuid(),
                        CartoonId = cartoon.Id,
                        Rank      = 1,
                        ImageSrc  = imageSrc
                    };
                    await _context.CartoonImages.AddAsync(cartoonImage);

                    await _context.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("BulkCartoonInsert", new { message = ex.Message }));
            }
            return(RedirectToAction("BulkCartoonInsert", new { message = "İşlem başarılı" }));
        }
        public async Task <IActionResult> Create(SendNotificationCpx notification)
        {
            notification.Id = Guid.NewGuid();
            _context.Add(notification);
            var result = await _context.SaveChangesAsync();

            if (result > 0)
            {
                string[] tokenList = new string[] { };
                var      query     = _context.NotificationToken.AsQueryable();
                if (notification.IsOnlyAndroid)
                {
                    query = query.Where(x => x.Platform == "android");
                    if (notification.LastLoginWithDate != 0)
                    {
                        query = query.Where(x => x.UpdateDate.AddDays(notification.LastLoginWithDate) < DateTime.Now);
                    }
                }
                else
                {
                    if (notification.LastLoginWithDate != 0)
                    {
                        query = query.Where(x => x.UpdateDate.AddDays(notification.LastLoginWithDate) < DateTime.Now);
                    }
                }
                query.Where(x => x.Settings.ProjectKey == "KarikaturMadeni");
                tokenList = await query.Select(x => x.Token).ToArrayAsync();

                if (tokenList.Length > 0)
                {
                    RestClient client  = new RestClient("https://exp.host/--/api/v2/push/send");
                    var        request = new RestRequest(Method.POST);
                    client.Timeout = -1;
                    request.AddHeader("content-type", "application/json");
                    request.AddParameter("application/json", JsonConvert.SerializeObject(new
                    {
                        to    = tokenList,
                        title = notification.Title,
                        body  = notification.Description,
                        sound = "default"
                    }), ParameterType.RequestBody);
                    IRestResponse response = client.Execute(request);
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("Id,LogoSrc,Name")] Drawer drawer)
        {
            if (ModelState.IsValid)
            {
                drawer.Id = Guid.NewGuid();
                _context.Add(drawer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            var allFiles = Directory.GetFiles($"{_env.WebRootPath}/Image/", "*.*", SearchOption.AllDirectories).ToList();

            for (int i = 0; i < allFiles.Count; i++)
            {
                allFiles[i] = allFiles[i].Replace(_env.WebRootPath, "");
            }
            ViewData["allFiles"] = allFiles;
            return(View(drawer));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("Id,CartoonId,ImageSrc")] CartoonImages cartoonImages)
        {
            if (ModelState.IsValid)
            {
                cartoonImages.Id = Guid.NewGuid();
                _context.Add(cartoonImages);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CartoonId"] = new SelectList(_context.Cartoon.OrderByDescending(x => x.Rank), "Id", "Id", cartoonImages.CartoonId);
            var allFiles = Directory.GetFiles($"{_env.WebRootPath}/Image/", "*.*", SearchOption.AllDirectories).ToList();

            for (int i = 0; i < allFiles.Count; i++)
            {
                allFiles[i] = allFiles[i].Replace(_env.WebRootPath, "");
            }
            ViewData["allFiles"] = allFiles;
            return(View(cartoonImages));
        }
예제 #12
0
        public async Task <ActionResult> SendPassword(Users users)
        {
            if (_env.IsDevelopment())
            {
                return(RedirectToAction("Index", new { pageType = 0, Email = users.Email, GetPassword = true }));
            }
            var password = Guid.NewGuid();
            var user     = _context.Users.FirstOrDefault(x => x.Email == users.Email);

            if (user != null && !string.IsNullOrEmpty(user.Email))
            {
                user.Password = password;
                user.PasswordExpirationDate = DateTime.Now.AddMinutes(10);
                _context.Update(user);
                if (await _context.SaveChangesAsync() > 0)
                {
                    var fromAddress = new MailAddress("*****@*****.**", "Karikatür - Admin Parola" + DateTime.Now.ToString());
                    var toAddress   = new MailAddress(users.Email, "Parola");

                    var smtp = new SmtpClient
                    {
                        Host                  = "smtp.gmail.com",
                        Port                  = 587,
                        EnableSsl             = true,
                        DeliveryMethod        = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials           = new NetworkCredential(fromAddress.Address, "xz06pl54Cer32.")
                    };
                    using (var message = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = "Parolanız - " + DateTime.Now.ToString(),
                        Body = "<p style='font-size:25px'>" + password + "</p>",
                        IsBodyHtml = true
                    })
                        try
                        {
                            smtp.Send(message);
                        }
                        catch (Exception err)
                        {
                            return(RedirectToAction("Index", new { pageType = 1, Email = users.Email, ErrorText = err.Message }));
                        }
                    return(RedirectToAction("Index", new { pageType = 0, Email = users.Email, GetPassword = true }));
                }
            }
            return(RedirectToAction("Index", new { pageType = 2, Email = users.Email }));
        }