Ejemplo n.º 1
0
        public async Task <IActionResult> Create(UserCreate userCreate, string[] roles)
        {
            if (roles.Count() == 0)
            {
                ViewBag.msg      = "يجب اختيار دور على الاقل ";
                userCreate.Roles = _context.Roles.ToList();
                return(View(userCreate));
            }
            if (ModelState.IsValid)
            {
                var user = _mapper.Map <UserCreate, AppUser>(userCreate);

                var result = await _userManager.CreateAsync(user, user.PhoneNumber);

                if (result.Succeeded)
                {
                    foreach (var role in roles)
                    {
                        await _userManager.AddToRoleAsync(user, role);
                    }
                    _f.Flash("success", "تم الحفظ بنجاح");
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(userCreate));
        }
        public async Task <IActionResult> CreateDoctor()
        {
            TempUser foundTempUser = (from tmpUsr in _db.TempUser where tmpUsr.Pesel == TempUser.Pesel select tmpUsr).FirstOrDefault();
            User     foundUser     = (from usr in _db.User where usr.Pesel == TempUser.Pesel select usr).FirstOrDefault();


            if (foundTempUser != null || foundUser != null)
            {
                _flasher.Flash(Types.Danger, "Lekarz o podanym numer PESEL już istnieje.", dismissable: true);
            }
            else if (!PeselChecksum(TempUser.Pesel))
            {
                _flasher.Flash(Types.Danger, "Podany pesel jest nieprawidłowy.", dismissable: true);
            }
            else
            {
                await _db.TempUser.AddAsync(TempUser);

                await _db.SaveChangesAsync();

                _flasher.Flash(Types.Success, "Pomyślnie zarejestrowano lekarza.", dismissable: true);
            }

            return(RedirectToAction("RegisterDoctor"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(EducationBodyCreateViewModel bodyEdu)
        {
            if (ModelState.IsValid)
            {
                string uniqFileName = null;
                if (bodyEdu.StampFile != null && bodyEdu.StampFile.Length > 0)
                {
                    if (IsFileValidate(bodyEdu.StampFile.FileName))
                    {
                        string uplouadsFolder = Path.Combine(_ihostingEnvironment.WebRootPath, "img/stamps");
                        uniqFileName = Guid.NewGuid().ToString() + "_" + bodyEdu.StampFile.FileName;
                        string filePath = Path.Combine(uplouadsFolder, uniqFileName);

                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            bodyEdu.StampFile.CopyTo(fileStream);
                        }
                    }
                    else
                    {
                        ViewBag.msg = "الصور المسموح بها يجب ان تكون بمتداد : " + "png , jpeg , jpg , gif , bmp ";

                        return(View(bodyEdu));
                    }
                }
                var educationalBody = new EducationalBody()
                {
                    Name       = bodyEdu.Name, City = bodyEdu.City,
                    EntityType = bodyEdu.EntityType, UserId = bodyEdu.UserId, Stamp = uniqFileName
                };
                _context.Add(educationalBody);
                await _context.SaveChangesAsync();

                _f.Flash("success", "تم الحفظ بنجاح");
                return(RedirectToAction(nameof(Index)));
            }
            var type = new List <EntityTypeForEducation>();

            var Institutes = new EntityTypeForEducation()
            {
                Name = "المعاهد والدور"
            };

            type.Add(Institutes);
            var Colleges = new EntityTypeForEducation()
            {
                Name = "الكليات"
            };

            type.Add(Colleges);

            ViewData["type"]   = new SelectList(type, "Name", "Name", bodyEdu.EntityType);
            ViewData["UserId"] = new SelectList(_context.Users.Include(u => u.UserRoles).Where(r => r.UserRoles.Any(a => a.Role.Name == "Supervisor")), "Id", "FullName", bodyEdu.UserId);
            return(View(bodyEdu));
        }
Ejemplo n.º 4
0
 public IActionResult Privacy()
 {
     _flasher.Primary("A minimalistic flash system message for ASP.NET Core MVC", dismissable: true);
     _flasher.Secondary("A minimalistic flash system message for ASP.NET Core MVC", dismissable: true);
     _flasher.Success("A minimalistic flash system message for ASP.NET Core MVC", dismissable: true);
     _flasher.Danger("A minimalistic flash system message for ASP.NET Core MVC", dismissable: true);
     _flasher.Flash(Types.Warning, "A minimalistic flash system message for ASP.NET Core MVC", dismissable: true);
     _flasher.Flash(Types.Info, "A minimalistic flash system message for ASP.NET Core MVC", dismissable: true);
     _flasher.Flash(Types.Light, "A minimalistic flash system message for ASP.NET Core MVC", dismissable: true);
     _flasher.Flash(Types.Dark, "A minimalistic flash system message for ASP.NET Core MVC", dismissable: true);
     return(View());
 }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,LocationName")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                _f.Flash("success", "تم الحفظ بنجاح");
                return(RedirectToAction(nameof(Index)));
            }
            return(View(city));
        }
Ejemplo n.º 6
0
        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";

            f.Flash("success", "Flash message system for ASP.NET MVC Core");

            return(RedirectToAction("Contact"));
        }
        public IActionResult PostLogin()
        {
            User foundUser =
                (from u in _db.User
                 where u.Pesel == User.Pesel && u.Password == User.Password
                 select u).FirstOrDefault();

            if (foundUser != null)
            {
                ClaimsIdentity identity = null;

                if (foundUser.IsAdmin)
                {
                    identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, $"{foundUser.FirstName} {foundUser.LastName}"),
                        new Claim(ClaimTypes.Role, "Admin"),
                        new Claim(ClaimTypes.NameIdentifier, foundUser.Pesel)
                    }, CookieAuthenticationDefaults.AuthenticationScheme);
                }
                else
                {
                    identity = new ClaimsIdentity(new[] {
                        new Claim(ClaimTypes.Name, $"{foundUser.FirstName} {foundUser.LastName}"),
                        new Claim(ClaimTypes.Role, "User"),
                        new Claim(ClaimTypes.NameIdentifier, foundUser.Pesel)
                    }, CookieAuthenticationDefaults.AuthenticationScheme);
                }

                var principal = new ClaimsPrincipal(identity);
                var login     = HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

                if (foundUser.IsAdmin)
                {
                    _flasher.Flash(Types.Info, "Zalogowano pomyślnie.", dismissable: true);
                    return(RedirectToAction("RegisterDoctor", "Register"));
                }

                _flasher.Flash(Types.Info, "Zalogowano pomyślnie.", dismissable: true);
                return(RedirectToAction("Index", "Home"));
            }

            _flasher.Flash(Types.Danger, "PESEL lub hasło niepoprawne.", dismissable: true);
            return(RedirectToAction("Login"));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> CreatePatient()
        {
            Patient foundPatient = _db.Patient.Where(p => p.Pesel == Patient.Pesel).FirstOrDefault();

            if (foundPatient != null)
            {
                if (foundPatient.NotPatientAnymore)
                {
                    foundPatient.NotPatientAnymore = false;
                    await _db.SaveChangesAsync();

                    _flasher.Flash(Types.Info, "Pomyślnie dodano nowego pacjenta.", dismissable: true);;
                }
                else
                {
                    _flasher.Flash(Types.Danger, "Pacjent jest już zapisany w systemie.", dismissable: true);
                }
            }
            else if (!PeselChecksum(Patient.Pesel))
            {
                _flasher.Flash(Types.Danger, "Podany pesel jest nieprawidłowy.", dismissable: true);
            }
            else
            {
                Patient.DateCreated    = DateTime.Now;
                Patient.CurrenctDoctor = _db.User.Where(usr => usr.Pesel == User.FindFirstValue(ClaimTypes.NameIdentifier))
                                         .Select(x => x).First();
                Patient.RoentgenPhoto = RoentgenGenerator.LoadRandomImage();

                TreatmentHistory th = new TreatmentHistory
                {
                    Doctor        = Patient.CurrenctDoctor,
                    Patient       = Patient,
                    TreatmentDate = DateTime.Now
                };

                await _db.Patient.AddAsync(Patient);

                await _db.TreatmentHistory.AddAsync(th);

                await _db.SaveChangesAsync();

                _flasher.Flash(Types.Info, "Pomyślnie dodano nowego pacjenta.", dismissable: true);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
0
        public IActionResult Create(Tsserver tsserver)
        {
            tsserver.TimePayment = (DateTime.Now.AddMonths(tsserver.TimePayment.Day));
            tsserver.MachineId   = 0;
            tsserver.Ip          = "127.0.0.1";
            tsserver.Port        = (new Random(DateTime.Now.Millisecond)).Next(65565);
            tsserver.User        = GetCurrentUser();

            _db.Tsservers.Add(tsserver);

            try
            {
                //var res = _teamspeakQueryClient.Client.Send($"servercreate virtualserver_name=TeamSpeak\\s]\\p[\\sServer " +
                //                                                                        $"virtualserver_port = {new Random().Next(2000, 65565)} " +
                //                                                                        $"virtualserver_maxclients = {tsserver.Slots}").Result;

                var res = _teamspeakQueryClient.Client.Send("servercreate virtualserver_name=TeamSpeak_Server virtualserver_port=2000 virtualserver_maxclients=32").Result;

                _db.SaveChanges();
            }
            catch (Exception e)
            {
                _logger.Log(LogLevel.Error, e.Message);
                _flasher.Flash("danger", "Не удалось создать сервер");
                return(RedirectToAction("Index", "Cabinet"));
            }

            _flasher.Flash("success", "Сервер успешно создан");

            return(RedirectToAction("Index", "Cabinet"));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> StatusUpdate(int Id)
        {
            var schedulingTripHead = await _context.SchedulingTripHead.FindAsync(Id);

            bool status = schedulingTripHead.Status;

            if (schedulingTripHead != null)
            {
                foreach (var s in await _context.SchedulingTripHead.ToListAsync())
                {
                    s.Status = false;
                    _context.SchedulingTripHead.Update(s);
                }
                await _context.SaveChangesAsync();
            }
            schedulingTripHead.Status = status == true ? false : true;
            _context.SchedulingTripHead.Update(schedulingTripHead);
            await _context.SaveChangesAsync();

            _f.Flash("success", "تم الحفظ بنجاح");
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 11
0
        public IActionResult Add(int id, int quantity, string returnUrl)
        {
            var cart = Session.GetObjectFromJson <CartModel>("Cart") ?? new CartModel();

            var product = cart.Items.FirstOrDefault(x => x.Id == id);

            if (product == default)
            {
                product = new CartItemModel
                {
                    Id       = id,
                    Quantity = 0
                };
                cart.Items.Add(product);
            }

            product.Quantity += quantity;
            Session.SetObjectAsJson("Cart", cart);
            _flasher.Flash(Types.Success, "Successfully added item to cart");

            return(Redirect(returnUrl));
        }
        public async Task <IActionResult> Add(AddProductModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.Image != null)
            {
                if (!Directory.Exists("Images"))
                {
                    Directory.CreateDirectory("Images");
                }

                var imgPath = $"/Images/{model.Image.FileName}";
                await using (var stream = new FileStream($"wwwroot{imgPath}", FileMode.Create))
                {
                    await model.Image.CopyToAsync(stream);
                }

                model.ImageUrl = imgPath;
            }

            await _dbContext.Products.AddAsync(new Product
            {
                Name        = model.Name,
                Description = model.Description ?? "",
                Price       = (int)Math.Round(model.Price * 100),
                Quantity    = model.Quantity,
                ImageUrl    = model.ImageUrl
            });

            await _dbContext.SaveChangesAsync();

            _flasher.Flash(Types.Success, "Product successfully added");

            return(RedirectToAction("Index"));
        }
        public void OnActionExecuting(ActionExecutingContext context)
        {
            object server_id;

            if (context.ActionArguments.ContainsKey("id"))
            {
                server_id = context.ActionArguments["id"];
            }
            else
            {
                server_id = (context.ActionArguments.First().Value as Tsserver)?.Id;
            }


            var tsserver     = db.Tsservers.Find(server_id);
            var current_user = userManager.GetUserAsync(context.HttpContext.User).Result;

            if (tsserver == null || tsserver.User.Id != current_user.Id)
            {
                flasher.Flash(Types.Danger, "Этот сервер не существует или не пренадлежит вам", true);
                context.Result = new RedirectToActionResult("Index", "Cabinet", null);
            }
        }
Ejemplo n.º 14
0
 public static void Secondary(this IFlasher flasher, string message, bool dismissable = false)
 {
     flasher.Flash(Types.Secondary, message, dismissable);
 }
Ejemplo n.º 15
0
 public static void Dark(this IFlasher flasher, string message, bool dismissable = false)
 {
     flasher.Flash(Types.Dark, message, dismissable);
 }
Ejemplo n.º 16
0
 public static void Light(this IFlasher flasher, string message, bool dismissable = false)
 {
     flasher.Flash(Types.Light, message, dismissable);
 }
Ejemplo n.º 17
0
 public static void Warning(this IFlasher flasher, string message, bool dismissable = false)
 {
     flasher.Flash(Types.Warning, message, dismissable);
 }
Ejemplo n.º 18
0
 public static void Success(this IFlasher flasher, string message, bool dismissable = false)
 {
     flasher.Flash(Types.Success, message, dismissable);
 }