Esempio n. 1
0
        public async Task <List <ResidentModel> > GetResidentsByPlanetNameAsync(string name)
        {
            List <ResidentModel> residents = new List <ResidentModel>();
            List <PlanetModel>   planets   = await GetAllPlanetsAsync();

            PlanetModel planet = planets.FirstOrDefault <PlanetModel>(x => x.PlanetName == name);

            foreach (string url in planet.PlanetResidents)
            {
                using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        string responseString = await response.Content.ReadAsStringAsync();

                        //response
                        ResidentModel resident = JsonConvert.DeserializeObject <ResidentModel>(responseString);
                        residents.Add(resident);
                    }
                    else
                    {
                        //Failed response
                        throw new Exception(response.ReasonPhrase);
                    }
                }
            }

            return(residents);
        }
Esempio n. 2
0
        // Метод изменения данных мастера в бд
        public static bool ChangeResident(RegisterMasterModel model)
        {
            try
            {
                using (UserContext dbUse = new UserContext())
                {
                    ResidentModel user = dbUse.ResidentModels.FirstOrDefault(t => t.Id == model.id);

                    if (user == null)
                    {
                        return(false);
                    }
                    user.Name       = model.Name;
                    user.Surname    = model.Surname;
                    user.Awards     = model.Awards;
                    user.Offers     = model.Offers;
                    user.Phone      = model.PhoneNumber;
                    user.Patronymic = model.Patronymic;
                    user.Experience = model.Expirience;
                    dbUse.ResidentModels.AddOrUpdate(user);
                    dbUse.SaveChanges();
                    return(true);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Esempio n. 3
0
        public void AddOrEditResident(ResidentModel newResident)
        {
            try
            {
                using (var ctx = new DBProjectEntities())
                {
                    var resident = ctx.Najemcy.Find(newResident.id_najemcy);

                    if (resident == null)
                    {
                        resident = ModelMapper.Mapper.Map <Najemcy>(newResident);
                        ctx.Najemcy.Add(resident);
                    }
                    else
                    {
                        resident.imie        = newResident.imie;
                        resident.nazwisko    = newResident.nazwisko;
                        resident.nr_telefonu = newResident.nr_telefonu;
                        resident.PESEL       = newResident.PESEL;
                    }

                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
 public void CreateResident(ResidentModel model)
 {
     if (model != null)
     {
         throw new ArgumentNullException();
     }
     _context.Add(model);
 }
Esempio n. 5
0
        public ActionResult <ResidentReadDTO> GetResidentByID(int id)
        {
            ResidentModel resident = _repo.GetResidentByID(id);

            if (resident == null)
            {
                return(NotFound());
            }
            return(Ok(_mapper.Map <ResidentReadDTO>(resident)));
        }
        public async Task <ResidentDTO> Post([FromBody, Required] ResidentDTO resident)
        {
            List <TestResult> testResultTypes = await TestResultModel.GetTestResultTypes();

            Resident res        = Resident.ConvertFromDTO(resident, testResultTypes);
            int      residentId = await ResidentModel.CreateResidentEntry(res);

            resident.ResidentID = residentId;
            return(resident);
        }
        public async Task <ActionResult> Put([FromRoute, Required] int residentId,
                                             [FromBody, Required] ResidentDTO resident)
        {
            List <TestResult> testResultTypes = await TestResultModel.GetTestResultTypes();

            Resident res = Resident.ConvertFromDTO(resident, testResultTypes);

            await ResidentModel.UpdateResidentEntry(residentId, res);

            return(new OkResult());
        }
        public ActionResult FindWorkPlaces()
        {
            List <string>            titles   = new List <string>();
            List <string>            addreses = new List <string>();
            List <WorkingPlaceModel> places   = Utilities.SendDbUtility.GetAllWorkingPlaces();
            List <bool> favorites             = new List <bool>();

            ResidentModel resident   = Utilities.SendDbUtility.GetResident(User.Identity.Name);
            int           userId     = 0;
            string        userCity   = "";
            string        userOffers = "";

            if (!Request.Cookies.AllKeys.Contains("SalonId"))
            {
                if (resident == null)
                {
                    return(RedirectToAction("LogOut", "Authentication"));
                }
                userId     = resident.Id;
                userCity   = resident.City;
                userOffers = resident.Offers;
            }
            else
            {
                places.RemoveAll(t => t.SalonId.ToString() != Request.Cookies["SalonId"].Value);

                favorites.ForEach(t => t = false);
            }


            List <SalonModel> salons = new List <SalonModel>();

            foreach (var place in places)
            {
                titles.Add(Utilities.SendDbUtility.GetSalonTitle(place.SalonId));
                addreses.Add(Utilities.SendDbUtility.GetSalonAdress(place.SalonId));
                favorites.Add(Utilities.SendDbUtility.CheckFavorite(place.Id, userId));
                salons.Add(Utilities.SendDbUtility.GetSalon(place.SalonId));
            }


            object[] x = new object[]
            {
                new DateModel(),
                places,
                titles,
                addreses,
                favorites,
                salons,
                userCity,
                userOffers
            };
            return(View(x));
        }
Esempio n. 9
0
        public IActionResult DeleteResident(int resID)
        {
            // find resident by id
            ResidentModel matchingRes = _context.residents.FirstOrDefault(res => res.id == resID);

            // removed matching resident
            _context.Remove(matchingRes);
            // save changes to database
            _context.SaveChanges();
            // return Content("Delete Resident");
            return(View("ViewAllResidents", _context));
        }
 public AddResidentUIEventArgs(
     RoutedEvent routedEvent,
     int id,
     string action,
     ResidentModel residentModel = null
     )
     : base(routedEvent)
 {
     _id            = id;
     _action        = action;
     _residentModel = residentModel;
 }
Esempio n. 11
0
 public static ResidentModel GetDataResident(string Email)
 {
     using (UserContext DbUse = new UserContext())
     {
         try
         {
             ResidentModel user = DbUse.ResidentModels.FirstOrDefault(t => t.Email == Email);
             return(user);
         }
         catch (Exception e)
         {
             return(null);
         }
     }
 }
Esempio n. 12
0
        public IActionResult AddResident(string resName, int resApartmentNumber, bool resHasPets)
        {
            // create new resident object
            ResidentModel newResident = new ResidentModel()
            {
                name = resName, apartmentNumber = resApartmentNumber, hasPets = resHasPets
            };

            // added new resident to database
            _context.Add(newResident);
            // save changes made (addition)
            _context.SaveChanges();
            // return Content($"Created Resident {resName}");
            return(View("ViewAllResidents", _context));
        }
Esempio n. 13
0
 public static bool CheckFavorite(int placeId, int residentId)
 {
     using (UserContext dbUse = new UserContext())
     {
         try
         {
             ResidentModel model = dbUse.ResidentModels.FirstOrDefault(t => t.Id == residentId);
             if (!model.Favorites.Contains(placeId.ToString() + ","))
             {
                 return(false);
             }
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
Esempio n. 14
0
 public static bool IsAdmin(string email)
 {
     try
     {
         using (UserContext dbUse = new UserContext())
         {
             ResidentModel user = dbUse.ResidentModels.FirstOrDefault(t => t.Email == email && t.IsAdmin);
             if (user == null)
             {
                 return(false);
             }
             return(true);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 15
0
 // Метод проверки существования номера телефона в бд
 public static bool CheckPhone(string Phone)
 {
     try
     {
         using (UserContext dbUse = new UserContext())
         {
             ResidentModel user = dbUse.ResidentModels.FirstOrDefault(t => t.Phone == Phone);
             if (user == null)
             {
                 return(false);
             }
             return(true);
         }
     }
     catch (Exception e)
     {
         return(true);
     }
 }
Esempio n. 16
0
        public IActionResult UpdateResidentPets(int resID, bool resHasPets)
        {
            // find resident by id
            ResidentModel matchingRes = _context.residents.FirstOrDefault(res => res.id == resID);

            if (matchingRes != null)
            {
                // update resident property
                matchingRes.hasPets = resHasPets;
                // save changes to database
                _context.SaveChanges();
                // return Content("Update Resident");
                return(View("ViewAllResidents", _context));
            }
            else
            {
                return(Content("Resident not found"));
            }
        }
Esempio n. 17
0
        public ResidentModel GetSingleResident(int residentId)
        {
            ResidentModel queryResult = null;

            try
            {
                using (var ctx = new DBProjectEntities())
                {
                    var resident = ctx.Najemcy.Find(residentId);

                    queryResult = ModelMapper.Mapper.Map <ResidentModel>(resident);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(queryResult);
        }
Esempio n. 18
0
        public ResidentModel GetSingleResident(string residentPesel)
        {
            ResidentModel queryResult = null;

            try
            {
                using (var ctx = new DBProjectEntities())
                {
                    var resident = ctx.Najemcy.FirstOrDefault(x => x.PESEL == residentPesel);

                    queryResult = ModelMapper.Mapper.Map <ResidentModel>(resident);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(queryResult);
        }
        public IHttpActionResult Post(ResidentModel baseRequest)
        {
            var user = SecurityHelper.CurrentPrincipal;

            if (user != null && user.OrgId != null)
            {
                baseRequest.OrganizationID = user.OrgId;
            }
            else
            {
                return(Ok(new BaseResponse <ResidentModel>()
                {
                    IsSuccess = false,
                    ResultMessage = "无法获取当前机构,请使用机构管理员登录."
                }));
            }
            var response = service.SaveResident(baseRequest);

            return(Ok(response));
        }
Esempio n. 20
0
 public static bool RemoveFavorite(int placeId, int residentId)
 {
     using (UserContext dbUse = new UserContext())
     {
         try
         {
             ResidentModel model = dbUse.ResidentModels.FirstOrDefault(t => t.Id == residentId);
             if (!model.Favorites.Contains(placeId.ToString() + ","))
             {
                 return(false);
             }
             model.Favorites = model.Favorites.Replace(placeId.ToString() + ",", "");
             dbUse.ResidentModels.AddOrUpdate(model);
             dbUse.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
Esempio n. 21
0
        // Метод проверки введенного логина и пароля
        public static bool ComparePassword(string Password, string Email)
        {
            try
            {
                using (UserContext dbUse = new UserContext())
                {
                    var           hashPass = GetData.GetHash(Password);
                    ResidentModel user     =
                        dbUse.ResidentModels.FirstOrDefault(t => t.Email == Email && t.Password == hashPass);

                    if (user == null)
                    {
                        return(false);
                    }
                    return(true);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Esempio n. 22
0
 // Метод изменения пароля
 public static bool ChangePassword(string Email, string newPass)
 {
     try
     {
         using (UserContext dbUse = new UserContext())
         {
             ResidentModel user = dbUse.ResidentModels.FirstOrDefault(t => t.Email == Email);
             if (user == null)
             {
                 return(false);
             }
             user.Password = GetData.GetHash(newPass);
             dbUse.ResidentModels.AddOrUpdate(user);
             dbUse.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Esempio n. 23
0
        private void ExecuteSaveCommand()
        {
            IPeopleModel tempModel = null;

            if (ResidentType == "Resident")
            {
                tempModel = new ResidentModel()
                {
                    Age        = Age,
                    PersonName = Resident,
                    Position   = Position,
                    Type       = "Resident"
                };
            }
            else if (ResidentType == "Soldier")
            {
                tempModel = new SoldierModel()
                {
                    Age        = Age,
                    PersonName = Resident,
                    Position   = Position,
                    Type       = "Soldier"
                };
            }

            if (tempModel != null)
            {
                ResidentUIEventArgs newEventArgs =
                    new ResidentUIEventArgs(
                        ResidentUIRoutedEvent,
                        Id,
                        "Save",
                        tempModel
                        );
                RaiseEvent(newEventArgs);
            }
        }
 public async Task <LocalIDSet <int> > LocalResidentIDs(int residentId)
 {
     return(await ResidentModel.PreviousAndNextResidentIds(residentId));
 }
 public async Task Delete([FromRoute, Required] int residentId)
 {
     await ResidentModel.DeleteResidentEntry(residentId);
 }
Esempio n. 26
0
        // PUT: api/Residents/5
        public void Put(int id, [FromBody] ResidentModel value)
        {
            var service = new ResidentsService();

            service.AddOrEditResident(value);
        }
Esempio n. 27
0
 public void DeleteResident(ResidentModel model)
 {
     _context.Remove(model);
 }
Esempio n. 28
0
        public BaseResponse <IList <ResidentModel> > QueryResident(BaseRequest <ResidentFilter> request)
        {
            var response      = new BaseResponse <IList <ResidentModel> >();
            var dicRepository = from a in unitOfWork.GetRepository <SYS_Dictionary>().dbSet.Where(a => a.ItemType == "K00.016")
                                join b in unitOfWork.GetRepository <SYS_DictionaryItem>().dbSet on a.DictionaryID equals b.DictionaryID
                                select b;

            var q = from r in unitOfWork.GetRepository <DC_Resident>().dbSet
                    join p in unitOfWork.GetRepository <DC_Person>().dbSet.Where(a => !a.IsDeleted) on r.PersonID equals p.PersonID
                    join a in unitOfWork.GetRepository <ORG_Area>().dbSet on r.AreaID equals a.AreaID into re
                    from n in re.DefaultIfEmpty()
                    join b in unitOfWork.GetRepository <ORG_Organization>().dbSet on r.OrganizationID equals b.OrganizationID
                    join h in dicRepository on p.Nationality equals h.ItemCode into nl
                    from i in nl.DefaultIfEmpty()
                    select new
            {
                r                 = r,
                Nationality       = p.Nationality,
                NationalityName   = i.ItemName,
                CensusAddressName = p.CensusAddressName,
                PersonName        = p.Name,
                Sex               = p.Sex,
                PhotoPath         = p.PhotoPath,
                Birthdate         = p.Birthdate,
                IdCard            = p.IdCard,
                PersonNo          = p.PersonNo,
                City              = p.City,
                Address           = p.Address,
                HouseNumber       = p.HouseNumber,
                Phone             = p.Phone,
                AreaID            = n.AreaID,
                AreaName          = n.AreaName,
                Lng               = p.Lng,
                Lat               = p.Lat,
                OrgName           = b.OrgName,
                Pinyin            = p.Pinyin
            };

            if (request != null)
            {
                if (request.Data.ResidentId.HasValue && request.Data.ResidentId != 0)
                {
                    q = q.Where(m => m.r.ResidentID == request.Data.ResidentId);
                }

                if (request.Data.ResidentIDs != null && request.Data.ResidentIDs.Length > 0)
                {
                    q = q.Where(m => request.Data.ResidentIDs.Contains(m.r.ResidentID));
                }
                if (request.Data.OrganizationID != 0)
                {
                    q = q.Where(m => m.r.OrganizationID == request.Data.OrganizationID);
                }
                if (request.Data.PersonId.HasValue && request.Data.PersonId != 0)
                {
                    q = q.Where(m => m.r.PersonID == request.Data.PersonId);
                }
                if (!string.IsNullOrEmpty(request.Data.PersonName))
                {
                    q = q.Where(m => m.PersonName.Contains(request.Data.PersonName.Trim()));
                }
                if (!string.IsNullOrEmpty(request.Data.Sex))
                {
                    q = q.Where(m => m.Sex == request.Data.Sex.Trim());
                }
                if (request.Data.HasLocation)
                {
                    q = q.Where(m => m.Lng.HasValue && m.Lat.HasValue);
                }

                if (!string.IsNullOrEmpty(request.Data.Keywords))
                {
                    q = q.Where(m => m.PersonName.ToUpper().Contains(request.Data.Keywords.ToUpper()) || m.IdCard.Contains(request.Data.Keywords) || m.Pinyin.Contains(request.Data.Keywords.ToUpper()));
                }
            }
            q = q.Where(w => w.r.IsDeleted == false && w.r.Status == "I");//状态为有效
            q = q.OrderByDescending(m => m.r.ResidentID);
            response.RecordsCount = q.Count();
            Action <IList> mapperResponse = (IList list) =>
            {
                response.Data = new List <ResidentModel>();
                foreach (dynamic item in list)
                {
                    ResidentModel resident = Mapper.DynamicMap <ResidentModel>(item.r);
                    resident.PersonName        = item.PersonName;
                    resident.Sex               = item.Sex;
                    resident.Nationality       = item.Nationality;
                    resident.NationalityName   = item.NationalityName;
                    resident.CensusAddressName = item.CensusAddressName;
                    resident.PhotoPath         = item.PhotoPath;
                    resident.Birthdate         = item.Birthdate;
                    resident.IdCard            = item.IdCard;
                    resident.PersonNo          = item.PersonNo;
                    resident.City              = item.City;
                    resident.Address           = item.Address;
                    resident.HouseNumber       = item.HouseNumber;
                    resident.Phone             = item.Phone;
                    resident.AreaID            = item.AreaID;
                    resident.AreaName          = item.AreaName;
                    resident.Lng               = item.Lng;
                    resident.Lat               = item.Lat;
                    resident.OrgName           = item.OrgName;
                    response.Data.Add(resident);
                }
            };

            if (request != null && request.PageSize > 0)
            {
                var list = q.Skip((request.CurrentPage - 1) * request.PageSize).Take(request.PageSize).ToList();
                response.PagesCount = GetPagesCount(request.PageSize, response.RecordsCount);
                mapperResponse(list);
            }
            else
            {
                var list = q.ToList();
                mapperResponse(list);
            }
            return(response);
        }
Esempio n. 29
0
        public BaseResponse <ResidentModel> SaveResident(ResidentModel request)
        {
            var residentRepository = base.unitOfWork.GetRepository <DC_Resident>();
            var personRepository   = base.unitOfWork.GetRepository <DC_Person>();
            //var per = personRepository.dbSet.FirstOrDefault(f => f.PersonID == request.PersonID && f.IsDeleted == false && f.AuditState == "A");
            var per = personRepository.dbSet.FirstOrDefault(f => f.PersonID == request.PersonID && f.IsDeleted == false);

            if (per == null)
            {
                return(new BaseResponse <ResidentModel>()
                {
                    IsSuccess = false, ResultMessage = string.Format("档案ID:{0} 无效!", request.PersonID)
                });
            }
            else if (per.AuditState == "U" && request.ResidentType == Enum.GetName(typeof(ResidentType), ResidentType.Signed))
            {
                return(new BaseResponse <ResidentModel>()
                {
                    IsSuccess = false, ResultMessage = "该档案尚未认证,无法设置为签约会员!"
                });
            }

            var ps = residentRepository.dbSet.FirstOrDefault(f => f.PersonID == request.PersonID && f.OrganizationID == request.OrganizationID && f.Status == "I" && request.IsDeleted == false);

            if (ps != null)
            {
                ps.AreaID       = request.AreaID;
                ps.ResidentType = request.ResidentType;
                residentRepository.Update(ps);
            }
            else
            {
                request.ResidentNo  = GenerateCode(EnumCodeKey.ResidentCode, EnumCodeRule.Year, "R", 4, request.OrganizationID);
                request.CheckInDate = DateTime.Now;
                request.Status      = "I";
                request.CreatedTime = DateTime.Now;
                var resident     = Mapper.DynamicMap <DC_Resident>(request);
                var idCard       = per.IdCard;
                var initPassword = idCard.Substring(idCard.Length - 6) + idCard;
                resident.Password = Util.Md5(initPassword);
                residentRepository.Insert(resident);
            }

            if (request.Lat.HasValue && request.Lng.HasValue)
            {
                per.Lng = request.Lng.Value;
                per.Lat = request.Lat.Value;
                personRepository.Update(per);
            }

            unitOfWork.Save();


            var person = residentRepository.dbSet.FirstOrDefault(f => f.PersonID == request.PersonID && f.OrganizationID == request.OrganizationID && f.Status == "I" && request.IsDeleted == false);

            if (person != null)
            {
                var str    = "{ \"ResidentID\":" + person.ResidentID + ",\"Name\":\"" + per.Name + "\",\"IdCard\":\"" + per.IdCard + "\",\"Sex\":" + per.Sex + "}";
                var qrPath = HttpContext.Current.Server.MapPath("~" + Constants.QrCodePath);
                if (!Directory.Exists(qrPath))
                {
                    Directory.CreateDirectory(qrPath);
                }
                Util.GetQRCode(str, qrPath + person.ResidentID.ToString() + ".png");
            }
            return(new BaseResponse <ResidentModel>()
            {
                IsSuccess = true, Data = request
            });
        }
Esempio n. 30
0
 public void UpdateResident(ResidentModel model)
 {
     //
 }