Example #1
0
 public static void BaseEntityToModel(Residence entity, ResidenceModel model)
 {
     model.Id     = entity.Id;
     model.Name   = entity.Name;
     model.Price  = entity.Price;
     model.UserId = entity.UserId;
 }
Example #2
0
 public static void AddressModelToEntity(ResidenceModel model, Residence entity)
 {
     entity.Address.City       = model.Address.City;
     entity.Address.Street     = model.Address.Street;
     entity.Address.State      = model.Address.State;
     entity.Address.PostalCode = model.Address.PostalCode;
 }
Example #3
0
 public void AddOrEditResidence(ResidenceModel newResidence)
 {
     try
     {
         using (var ctx = new DBProjectEntities())
         {
             var residence = ctx.Mieszkania.FirstOrDefault(x => x.id_budynku == newResidence.id_budynku && x.id_mieszkania == newResidence.id_mieszkania);
             if (residence == null)  //DB did not find any record like provided one. Add it.
             {
                 residence = ModelMapper.Mapper.Map <Mieszkania>(newResidence);
                 ctx.Mieszkania.Add(residence);
             }
             else//There's a record that contains the residence already - modify it.
             {
                 residence.numer  = newResidence.numer;
                 residence.metraz = newResidence.metraz;
                 residence.opis   = newResidence.opis;
                 //ctx.Entry(residence).State = EntityState.Modified;
             }
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Example #4
0
 public static void AddressEntityToModel(Residence entity, ResidenceModel model)
 {
     model.Address.City       = entity.Address.City;
     model.Address.Street     = entity.Address.Street;
     model.Address.State      = entity.Address.State;
     model.Address.PostalCode = entity.Address.PostalCode;
 }
Example #5
0
 public static void BaseModelToEntity(ResidenceModel model, Residence entity)
 {
     entity.Id     = model.Id;
     entity.Name   = model.Name;
     entity.Price  = model.Price;
     entity.UserId = model.UserId;
 }
Example #6
0
        public static ResidenceModel EntityToModel(Residence entity)
        {
            ResidenceModel model = new ResidenceModel()
            {
                ResidenceCategories = new List <CategoryModel>(),
                ResidenceCategoryId = new List <int>(),
                Images      = new List <string>(),
                Address     = new AddressModel(),
                UserDetails = new UserModel()
            };

            if (entity != null)
            {
                BaseEntityToModel(entity, model);
                AddressEntityToModel(entity, model);
                ImagesEntityToModel(entity, model);
                CategoriesEntityToModel(entity, model);

                if (entity.User != null)
                {
                    UserDetailsEntityToModel(entity, model);
                }
            }

            return(model);
        }
Example #7
0
 public static void ImagesEntityToModel(Residence entity, ResidenceModel model)
 {
     foreach (var item in entity.ResidenceImages)
     {
         model.Images.Add(item.ImageName);
     }
 }
        public override void Init(object initData)
        {
            base.Init(initData);

            Item = (ResidenceModel)initData;
           

        }
        public IActionResult Create()
        {
            ResidenceModel model = new ResidenceModel
            {
                ResidenceCategories = _iCategoryBLL.GetAllCategories()
            };

            return(View("Create", model));
        }
        public async Task <IActionResult> Edit(int id, ResidenceModel model, List <IFormFile> uploadImages)
        {
            model.ResidenceCategories = _iCategoryBLL.GetAllCategories();
            model.UserId = Convert.ToInt32(User.FindFirst(ClaimTypes.SerialNumber).Value);

            var authorizationResult = await _iAuthorizationService.AuthorizeAsync(User, model, Constants.Update);

            if (authorizationResult.Succeeded)
            {
                if (ModelState.IsValid)
                {
                    if (uploadImages.Count != 0)
                    {
                        _iResidenceBLL.RemoveResidenceImage(_iHostingEnvironment.ContentRootPath + Constants.wwwroot, id);

                        model.Images = new List <string>();

                        try
                        {
                            foreach (var image in uploadImages)
                            {
                                await ImageProcesser.UploadeAndResize(_iHostingEnvironment, image);

                                model.Images.Add(ImageProcesser.ReturnFileTarget());
                            }
                        }
                        catch (Exception e)
                        {
                            ModelState.AddModelError("Images", e.Message);

                            return(View(model));
                        }
                    }

                    _iResidenceBLL.UpdateResidence(model);

                    return(RedirectToAction("Items"));
                }
                else
                {
                    return(View(model));
                }
            }
            else if (User.Identity.IsAuthenticated)
            {
                return(new ForbidResult());
            }
            else
            {
                return(new ChallengeResult());
            }
        }
Example #11
0
        public static void CategoriesModelToEntity(ResidenceModel model, Residence entity)
        {
            foreach (var id in model.ResidenceCategoryId)
            {
                var itemCategory = new ResidenceCategory
                {
                    ResidenceId = entity.Id
                };

                itemCategory.CategoryId = id;
                entity.ResidenceCategories.Add(itemCategory);
            }
        }
Example #12
0
        public static void CategoriesEntityToModel(Residence entity, ResidenceModel model)
        {
            foreach (var item in entity.ResidenceCategories)
            {
                model.ResidenceCategoryId.Add(item.CategoryId);

                var itemCategory = new CategoryModel
                {
                    Id = item.CategoryId
                };

                itemCategory.Name = item.Category.Name;
                model.ResidenceCategories.Add(itemCategory);
            }
        }
Example #13
0
        public static void ImagesModelToEntity(ResidenceModel model, Residence entity)
        {
            if (model.Images != null)
            {
                foreach (var image in model.Images)
                {
                    var itemImage = new ResidenceImage
                    {
                        ResidenceId = entity.Id
                    };

                    itemImage.ImageName = image;
                    entity.ResidenceImages.Add(itemImage);
                }
            }
        }
Example #14
0
        public bool CreateResidence(ResidenceModel model)
        {
            var entity = ResidenceConverter.ModelToEntity(model);

            if (model.Images == null)
            {
                ResidenceImage residenceImage = new ResidenceImage()
                {
                    ResidenceId = entity.Id,
                    ImageName   = "https://i.imgur.com/vd8iZDs.jpg"
                };

                entity.ResidenceImages.Add(residenceImage);
            }

            return(_iResidenceDAO.CreateResidence(entity));
        }
Example #15
0
        public static Residence ModelToEntity(ResidenceModel model)
        {
            Residence entity = new Residence()
            {
                ResidenceCategories = new List <ResidenceCategory>(),
                Address             = new Address(),
                ResidenceImages     = new List <ResidenceImage>()
            };

            if (model != null)
            {
                BaseModelToEntity(model, entity);
                AddressModelToEntity(model, entity);
                ImagesModelToEntity(model, entity);
                CategoriesModelToEntity(model, entity);
            }

            return(entity);
        }
Example #16
0
        public bool UpdateResidence(ResidenceModel model)
        {
            var entity = _iResidenceDAO.GetResidence(model.Id);

            entity.Name  = model.Name;
            entity.Price = model.Price;
            ResidenceConverter.AddressModelToEntity(model, entity);

            if (model.Images != null)
            {
                entity.ResidenceImages = new List <ResidenceImage>();
                ResidenceConverter.ImagesModelToEntity(model, entity);
            }

            entity.ResidenceCategories = new List <ResidenceCategory>();
            ResidenceConverter.CategoriesModelToEntity(model, entity);

            return(_iResidenceDAO.UpdateResidence(entity));
        }
Example #17
0
        /// <summary>
        /// Return existing <see cref="Residence"/> by supplied owner name, if not locally cached it will be retrieved from the database.
        /// </summary>
        public async Task <Residence> GetResidence(string name)
        {
            if (ownerCache.TryGetValue(name, out ulong residenceId))
            {
                return(GetCachedResidence(residenceId));
            }

            ResidenceModel model = await DatabaseManager.Instance.CharacterDatabase.GetResidence(name);

            if (model == null)
            {
                return(null);
            }

            var residence = new Residence(model);

            residences.TryAdd(residence.Id, residence);
            ownerCache.TryAdd(name, residence.Id);
            return(residence);
        }
Example #18
0
        public ResidenceModel GetSingleResidenceByNumber(int buildingId, int residenceNumber)
        {
            var residence = new ResidenceModel();

            try
            {
                using (var ctx = new DBProjectEntities())
                {
                    var queryResult = ctx.Mieszkania.FirstOrDefault(x => x.id_budynku == buildingId && x.numer == residenceNumber);

                    residence = ModelMapper.Mapper.Map <ResidenceModel>(queryResult);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(residence);
        }
Example #19
0
        /// <summary>
        /// Return existing <see cref="Residence"/> by supplied residence id, if not locally cached it will be retrieved from the database.
        /// </summary>
        public async Task <Residence> GetResidence(ulong residenceId)
        {
            Residence residence = GetCachedResidence(residenceId);

            if (residence != null)
            {
                return(residence);
            }

            ResidenceModel model = await DatabaseManager.Instance.CharacterDatabase.GetResidence(residenceId);

            if (model == null)
            {
                return(null);
            }

            residence = new Residence(model);
            residences.TryAdd(residence.Id, residence);
            ownerCache.TryAdd(model.Character.Name, residence.Id);
            return(residence);
        }
Example #20
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                var userResidence = new ResidenceModel {
                };
                _context.ResidenceModel.Add(userResidence);
                _context.SaveChanges();

                var user = new ApplicationUser
                {
                    UserName    = model.Email,
                    Email       = model.Email,
                    ResidenceId = userResidence.Id
                };
                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);


                    await _userManager.AddToRoleAsync(user, "Patient");

                    await _signInManager.SignInAsync(user, false);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }
            return(View());
        }
        public async Task <IActionResult> Create(ResidenceModel model, List <IFormFile> uploadImages)
        {
            model.ResidenceCategories = _iCategoryBLL.GetAllCategories();

            if (ModelState.IsValid)
            {
                model.UserId = Convert.ToInt32(User.FindFirst(ClaimTypes.SerialNumber).Value);

                if (uploadImages.Count != 0)
                {
                    model.Images = new List <string>();

                    try
                    {
                        foreach (var image in uploadImages)
                        {
                            await ImageProcesser.UploadeAndResize(_iHostingEnvironment, image);

                            model.Images.Add(ImageProcesser.ReturnFileTarget());
                        }
                    }
                    catch (Exception e)
                    {
                        ModelState.AddModelError("Images", e.Message);

                        return(View(model));
                    }
                }

                _iResidenceBLL.CreateResidence(model);

                return(RedirectToAction("Items"));
            }
            else
            {
                return(View(model));
            }
        }
Example #22
0
 public static void UserDetailsEntityToModel(Residence entity, ResidenceModel model)
 {
     model.UserDetails.Email     = entity.User.Email;
     model.UserDetails.FirstName = entity.User.FirstName;
     model.UserDetails.Phone     = entity.User.Phone;
 }
Example #23
0
        // PUT: api/Faults/5
        public void Put(int id, [FromBody] ResidenceModel value)
        {
            var service = new ResidencesService();

            service.AddOrEditResidence(value);
        }
Example #24
0
        public async void Initialize(IConfiguration configuration)
        {
            var serviceScope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope();
            var roleManager  = serviceScope.ServiceProvider.GetService <RoleManager <ApplicationRole> >();

            string[] roleNames = { RoleNames.Admin, RoleNames.Manager, RoleNames.Patient, RoleNames.Doctor, RoleNames.Clerk };

            var context = serviceScope.ServiceProvider.GetService <ApplicationDbContext>();
            await context.Database.EnsureCreatedAsync();

            foreach (var roleName in roleNames)
            {
                var role = await roleManager.RoleExistsAsync(roleName);

                if (!role)
                {
                    await roleManager.CreateAsync(new ApplicationRole(roleName));
                }
            }

            // Create admin account
            var userManager = serviceScope.ServiceProvider.GetService <UserManager <ApplicationUser> >();

            var userAdmin = new ApplicationUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                ResidenceId    = 1
            };

            string userPassword = "******";

            if (await userManager.FindByEmailAsync("*****@*****.**") == null)
            {
                context.ResidenceModel.Add(new ResidenceModel {
                });
                context.SaveChanges();

                var success = await userManager.CreateAsync(userAdmin, userPassword);

                if (success.Succeeded)
                {
                    await userManager.AddToRoleAsync(userAdmin, RoleNames.Admin);
                }
                context.SaveChanges();
            }

            var userDoctors = new ApplicationUser[]
            {
                new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Henryk",
                    LastName       = "Kowalski",
                    PIN            = "66071496752",
                    PhoneNum       = "345663874",
                    Sex            = "Mężczyzna",
                    ResidenceId    = 2
                },

                new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Maria",
                    LastName       = "Nowak",
                    PIN            = "72062607345",
                    PhoneNum       = "796256840",
                    Sex            = "Kobieta",
                    ResidenceId    = 3
                }
            };

            foreach (ApplicationUser user in userDoctors)
            {
                if (!context.ApplicationUser.Any(o => o.UserName == user.UserName))
                {
                    context.ResidenceModel.Add(new ResidenceModel {
                    });
                    context.SaveChanges();

                    var success = await userManager.CreateAsync(user, userPassword);

                    if (success.Succeeded)
                    {
                        await userManager.AddToRoleAsync(user, RoleNames.Doctor);
                    }

                    context.SaveChanges();
                }
            }

            var doctors = new DoctorModel[]
            {
                new DoctorModel {
                    Specialization = "Endokrynologia",
                    UserId         = userDoctors[0].Id
                },
                new DoctorModel {
                    Specialization = "Alergologia",
                    UserId         = userDoctors[1].Id
                }
            };

            foreach (DoctorModel doctor in doctors)
            {
                if (!context.DoctorModel.Any(o => o.Specialization == doctor.Specialization))
                {
                    context.DoctorModel.Add(doctor);
                    context.SaveChanges();
                }
            }

            var userPatients = new ApplicationUser[]
            {
                new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Tomasz",
                    LastName       = "Adamski",
                    PIN            = "79022405942",
                    PhoneNum       = "819458234",
                    Sex            = "Mężczyzna",
                    ResidenceId    = 4
                },

                new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Agata",
                    LastName       = "Walczyk",
                    PIN            = "69091295041",
                    PhoneNum       = "758399405",
                    Sex            = "Kobieta",
                    ResidenceId    = 5
                },

                new ApplicationUser
                {
                    UserName       = "******",
                    Email          = "*****@*****.**",
                    EmailConfirmed = true,
                    FirstName      = "Tobiasz",
                    LastName       = "Adamski",
                    PIN            = "78031895332",
                    PhoneNum       = "199405394",
                    Sex            = "Mężczyzna",
                    ResidenceId    = 6
                },
            };

            string patientPassword = "******";

            foreach (ApplicationUser userPatient in userPatients)
            {
                if (!context.ApplicationUser.Any(o => o.UserName == userPatient.UserName))
                {
                    var residence = new ResidenceModel
                    {
                        Country     = "Polska",
                        Street      = "Krakowska",
                        City        = "Kraków",
                        PostalCode  = "31-066",
                        BuildingNum = "30",
                        FlatNum     = "4"
                    };

                    context.ResidenceModel.Add(residence);
                    context.SaveChanges();

                    var success = await userManager.CreateAsync(userPatient, patientPassword);

                    if (success.Succeeded)
                    {
                        await userManager.AddToRoleAsync(userPatient, RoleNames.Patient);
                    }

                    var patient = new PatientModel
                    {
                        UserId = userPatient.Id
                    };

                    context.PatientModel.Add(patient);
                    context.SaveChanges();

                    var patientCard = new PatientCardModel
                    {
                        Date      = "17/05/2018",
                        PatientId = patient.Id
                    };

                    context.PatientCardModel.Add(patientCard);
                    context.SaveChanges();
                }
            }

            var userClerk = new ApplicationUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                FirstName      = "Edyta",
                LastName       = "Kotarska",
                PIN            = "86062702842",
                PhoneNum       = "850904195",
                Sex            = "Kobieta",
                ResidenceId    = 7
            };

            if (!context.ApplicationUser.Any(o => o.UserName == userClerk.UserName))
            {
                context.ResidenceModel.Add(new ResidenceModel {
                });
                context.SaveChanges();

                var success = await userManager.CreateAsync(userClerk, userPassword);

                if (success.Succeeded)
                {
                    await userManager.AddToRoleAsync(userClerk, RoleNames.Clerk);
                }

                var clerk = new ClerkModel
                {
                    UserId = userClerk.Id
                };

                context.ClerkModel.Add(clerk);
                context.SaveChanges();
            }

            var workHours = new WorkHoursModel[]
            {
                new WorkHoursModel {
                    DayofWeek = "wtorek",
                    StartHour = "12:55",
                    EndHour   = "16:40",
                    DoctorId  = doctors[0].Id
                },

                new WorkHoursModel {
                    DayofWeek = "czwartek",
                    StartHour = "9:30",
                    EndHour   = "13:00",
                    DoctorId  = doctors[1].Id
                }
            };

            foreach (WorkHoursModel workHour in workHours)
            {
                if (!context.WorkHours.Any(o => o.DayofWeek == workHour.DayofWeek && o.StartHour == workHour.StartHour))
                {
                    context.WorkHours.Add(workHour);
                    context.SaveChanges();
                }
            }

            var visits = new AppointmentModel[]
            {
                new AppointmentModel
                {
                    DateOfApp = "8/05/2018",
                    DoctorId  = doctors[0].Id
                },

                new AppointmentModel
                {
                    DateOfApp = "15/05/2018",
                    DoctorId  = doctors[0].Id
                },

                new AppointmentModel
                {
                    DateOfApp = "22/05/2018",
                    DoctorId  = doctors[0].Id
                },

                new AppointmentModel
                {
                    DateOfApp = "05/06/2018",
                    DoctorId  = doctors[0].Id
                },

                new AppointmentModel
                {
                    DateOfApp = "24/05/2018",
                    DoctorId  = doctors[1].Id
                },

                new AppointmentModel
                {
                    DateOfApp = "07/06/2018",
                    DoctorId  = doctors[1].Id
                },

                new AppointmentModel
                {
                    DateOfApp = "14/06/2018",
                    DoctorId  = doctors[1].Id
                }
            };

            foreach (AppointmentModel app in visits)
            {
                if (!context.AppointmentModel.Any(o => o.DateOfApp == app.DateOfApp))
                {
                    context.AppointmentModel.Add(app);
                    context.SaveChanges();
                }
            }
        }