示例#1
0
        public HttpResponseMessage Delete(HttpRequestMessage request, FamilyViewModel family)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                              .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    var familyDb = _familyRepository.GetSingle(family.ID);
                    if (familyDb == null)
                        response = request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid family.");
                    else
                    {
                        familyDb.UpdateFamily(family);
                        _familyRepository.Delete(familyDb);

                        _unitOfWork.Commit();
                        response = request.CreateResponse<FamilyViewModel>(HttpStatusCode.OK, family);
                    }
                }

                return response;
            });
        }
示例#2
0
        public HttpResponseMessage Create(HttpRequestMessage request, FamilyViewModel family)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                              .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    Family newFamily = new Family();
                    newFamily.UpdateFamily(family);
                    _familyRepository.Add(newFamily);

                    _unitOfWork.Commit();

                    // Update view model
                    family = Mapper.Map<Family, FamilyViewModel>(newFamily);
                    response = request.CreateResponse<FamilyViewModel>(HttpStatusCode.Created, family);
                }

                return response;
            });
        }
        public IHttpActionResult GetParentFamily()
        {
            ApplicationUser user        = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
            Family          family      = db.Families.FirstOrDefault(f => f.Email == user.Email);
            List <String>   childrenUrl = new List <string>();
            List <String>   parentUrl   = new List <string>();

            foreach (Child child in family.Children)
            {
                childrenUrl.Add(Url.Link("getChildren", new { id = child.ChildrenId }));
            }
            foreach (Parent parent in family.Parents)
            {
                parentUrl.Add(Url.Link("getParent", new { id = parent.ParentId }));
            }
            FamilyViewModel familyViewModel = new FamilyViewModel
            {
                ContactNumber   = family.ContactNumber,
                Email           = family.Email,
                AddressLine     = family.AddressLine,
                AddressArea     = family.AddressArea,
                AddressPostcode = family.AddressPostcode,
                Children        = childrenUrl,
                Parent          = parentUrl
            };

            if (family == null)
            {
                return(NotFound());
            }

            return(Ok(familyViewModel));
        }
示例#4
0
        public IHttpActionResult Delete(FamilyViewModel model)
        {
            if (!CanEditFamily(model.FamilyID))
            {
                return(BadRequest("You do not have rights to delete this family"));
            }

            bool logOut = false;

            using (bkContext context = new bkContext())
            {
                using (var tnx = context.Database.BeginTransaction())
                {
                    try
                    {
                        context.bk_DeleteFamily(model.FamilyID);
                        tnx.Commit();
                    }
                    catch
                    {
                        tnx.Rollback();
                        throw;
                    }

                    //make sure logged in member is still active on the system
                    logOut = !context.Members.Any(x => x.MemberID == LoggedInMemberId);
                }
            }

            return(Ok(logOut));
        }
        public IHttpActionResult GetFamily(int id)
        {
            Family        family      = db.Families.Find(id);
            List <String> childrenUrl = new List <string>();
            List <String> parentUrl   = new List <string>();

            foreach (Child child in family.Children)
            {
                childrenUrl.Add(Url.Link("getChildren", new { id = child.ChildrenId }));
            }
            foreach (Parent parent in family.Parents)
            {
                parentUrl.Add(Url.Link("getParent", new { id = parent.ParentId }));
            }
            FamilyViewModel familyViewModel = new FamilyViewModel
            {
                ContactNumber   = family.ContactNumber,
                Email           = family.Email,
                AddressLine     = family.AddressLine,
                AddressArea     = family.AddressArea,
                AddressPostcode = family.AddressPostcode,
                Children        = childrenUrl,
                Parent          = parentUrl
            };

            if (family == null)
            {
                return(NotFound());
            }

            return(Ok(familyViewModel));
        }
        public ActionResult SaveMember(FamilyViewModel model, HttpPostedFileBase fPic)
        {
            ResponseMsg response = new ResponseMsg();

            try
            {
                int candidateId = clsBusinessLogic.SaveFamily(model);
                if (candidateId > 0)
                {
                    if (fPic != null)
                    {
                        fPic.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["CandidatePhotoPath"]) + candidateId + System.IO.Path.GetExtension(fPic.FileName));
                        clsBusinessLogic.UpdateFamilyPhoto(candidateId, candidateId + System.IO.Path.GetExtension(fPic.FileName));
                    }
                }
                else
                {
                    response.IsSuccess     = false;
                    response.ResponseValue = "Error while saving candidate, Please try after sometime.";
                    return(Json(response));
                }

                response.IsSuccess     = true;
                response.ResponseValue = "";
            }
            catch (Exception ex)
            {
                response.IsSuccess     = false;
                response.ResponseValue = "Error : " + ex.Message;
            }
            return(Json(response));
        }
        public ActionResult FamilyView()
        {
            FamilyViewModel model = new FamilyViewModel();

            model.FamilyList = db.family;
            return(View(model));
        }
示例#8
0
        public ActionResult AddToFamily(int id, bool isPrimary = false)
        {
            var u = new FamilyViewModel();

            u.IncIndex  = id;
            u.IsPrimary = isPrimary;
            return(PartialView("AddToFamily", u));
        }
示例#9
0
        public FamilyPage()
        {
            InitializeComponent();
            //<StyleSheet Source="/Vaccine.css" />
            // this.Resources.Add(StyleSheet.FromAssemblyResource(IntrospectionExtensions.GetTypeInfo(typeof(FamilyPage)).Assembly, "VaccineCalendar.Vaccine.css"));


            BindingContext = viewModel = new FamilyViewModel();
        }
        public ActionResult Create(FamilyViewModel familyViewModel)
        {
            if (ModelState.IsValid)
            {
                _familyManager.IsRegister(familyViewModel);
                return(RedirectToAction("Index", "Family"));
            }

            return(View(familyViewModel));
        }
示例#11
0
        public FamilyViewModel CreateViewModel(Family f)
        {
            var viewModel = new FamilyViewModel()
            {
                Id   = f.Id,
                Name = f.Name
            };

            return(viewModel);
        }
        private void buttonOk_Click(object sender, RoutedEventArgs e)
        {
            if (FamilyNameEN.Text == "" || FamilyNameRU.Text == "")
            {
                MessageBox.Show("Заполните форму", "ПРЕДУПРЕЖДЕНИЕ", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                string strRU  = FamilyNameRU.Text.ToLower();
                string strEN  = FamilyNameEN.Text.ToLower();
                bool   RUisOK = true;
                bool   ENisOK = true;

                foreach (char b in strEN)
                {
                    if (b >= 'а' && b <= 'я')
                    {
                        MessageBox.Show("Поле \"ЛАТИНСКОЕ НАЗВАНИЕ\" должно содержать только литинские символы!!!", "ПРЕДУПРЕЖДЕНИЕ", MessageBoxButton.OK, MessageBoxImage.Information);
                        ENisOK = false;
                        break;
                    }
                }
                foreach (char a in strRU)
                {
                    if (a >= 'a' && a <= 'z')
                    {
                        MessageBox.Show("Поле \"РУССКОЕ НАЗВАНИЕ\" должно содержать только символы кириллицы!!!", "ПРЕДУПРЕЖДЕНИЕ", MessageBoxButton.OK, MessageBoxImage.Information);
                        RUisOK = false;
                        break;
                    }
                }
                if (RUisOK && ENisOK)
                {
                    try
                    {
                        var familyVM = new FamilyViewModel();
                        familyVM.NameEN = FamilyNameEN.Text;
                        familyVM.NameRU = FamilyNameRU.Text;
                        var form = (FormViewModel)FormName.SelectedItem;
                        form.Families.Add(familyVM);
                        formService.AddFamilyToForm(form.ID, familyVM);
                        form.Families.Add(familyVM);
                        Close();
                    }
                    catch (System.Data.Entity.Infrastructure.DbUpdateException)
                    {
                        MessageBox.Show("Проверьте \"ЛАТИНСКОЕ НАЗВАНИЕ\" и \"РУССКОЕ НАЗВАНИЕ\" возможно они уже присутствуют в базе данных!!!", "ПРЕДУПРЕЖДЕНИЕ", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.InnerException.Message, "ПРЕДУПРЕЖДЕНИЕ", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
            }
        }
示例#13
0
        public ActionResult SaveFamily(FamilyViewModel model, HttpPostedFileBase fPicMainMember, HttpPostedFileBase fPicFather, HttpPostedFileBase fPicMother, List <HttpPostedFileBase> fPicMembers)
        {
            ResponseMsg response = new ResponseMsg();

            try
            {
                var newId = Guid.NewGuid();
                if (fPicMainMember != null)
                {
                    newId = Guid.NewGuid();
                    fPicMainMember.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["FamilyPhotoPath"]) + newId + System.IO.Path.GetExtension(fPicMainMember.FileName));
                    model.family.PhotoPath = newId + System.IO.Path.GetExtension(fPicMainMember.FileName);
                }
                if (fPicFather != null)
                {
                    newId = Guid.NewGuid();
                    fPicFather.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["FamilyPhotoPath"]) + newId + System.IO.Path.GetExtension(fPicFather.FileName));
                    model.family.FatherImagePath = newId + System.IO.Path.GetExtension(fPicFather.FileName);
                }
                if (fPicMother != null)
                {
                    newId = Guid.NewGuid();
                    fPicMother.SaveAs(Server.MapPath(ConfigurationManager.AppSettings["FamilyPhotoPath"]) + newId + System.IO.Path.GetExtension(fPicMother.FileName));
                    model.family.MotherImagePath = newId + System.IO.Path.GetExtension(fPicMother.FileName);
                }
                if (fPicMembers != null && fPicMembers.Count > 0)
                {
                    for (var i = 0; i < fPicMembers.Count; i++)
                    {
                        if (fPicMembers[i] != null)
                        {
                            newId = Guid.NewGuid();
                            fPicMembers[i].SaveAs(Server.MapPath(ConfigurationManager.AppSettings["FamilyPhotoPath"]) + newId + System.IO.Path.GetExtension(fPicMembers[i].FileName));
                            model.FamilyMembers[i].PhotoPath = newId + System.IO.Path.GetExtension(fPicMembers[i].FileName);
                        }
                    }
                }
                int candidateId = clsBusinessLogic.SaveFamily(model);
                if (!(candidateId > 0))
                {
                    response.IsSuccess     = false;
                    response.ResponseValue = "Error while saving candidate, Please try after sometime.";
                    return(Json(response));
                }

                response.IsSuccess     = true;
                response.ResponseValue = "";
            }
            catch (Exception ex)
            {
                response.IsSuccess     = false;
                response.ResponseValue = "Error : " + ex.Message;
            }
            return(Json(response));
        }
示例#14
0
        public IHttpActionResult Edit([FromBody] FamilyViewModel family)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _familyService.Edit(_mapper.Map <Family>(family));

            return(Ok());
        }
示例#15
0
        public IHttpActionResult Save(FamilyViewModel model)
        {
            if (!CanEditFamily(model.FamilyID))
            {
                return(BadRequest("You do not have permission to edit this family"));
            }

            using (bkContext context = new bkContext())
            {
                Family family = context.Families.Where(f => f.FamilyID == model.FamilyID).FirstOrDefault();
                if (family == null)
                {
                    return(BadRequest("Family record cannot be loaded. Please try again later"));
                }

                if (model.HeadOfFamilyID == 0)
                {
                    return(BadRequest("please provide Head Of Family"));
                }

                if (!family.FamilyMemberAssociations.Any(x => x.MemberId == model.HeadOfFamilyID))
                {
                    return(BadRequest("Supplied Head Of Family is not part of family"));
                }

                if (!family.FamilyMemberAssociations.Any(x => x.MemberId == model.HeadOfFamilyID && x.Approved))
                {
                    return(BadRequest("Head Of family is not approved member of family"));
                }

                if (context.Families.Any(x => x.FamilyID != model.FamilyID && x.HeadOfFamilyID == model.HeadOfFamilyID))
                {
                    return(BadRequest("Selected Head Of Family is already a Head Of Family for another family. Please select other member as head of family."));
                }

                family.FamilyNative   = model.FamilyNative;
                family.Address1       = model.Address1;
                family.Address2       = model.Address2;
                family.CategoryID     = model.CategoryID;
                family.City           = model.City;
                family.District       = model.District;
                family.Country        = model.Country;
                family.NukhID         = model.NukhID;
                family.PostalCode     = model.PostalCode;
                family.State          = model.State;
                family.HeadOfFamilyID = model.HeadOfFamilyID;
                family.ModifiedOn     = DateTime.Now;
                family.ModifiedBy     = LoggedInMemberId;

                context.SaveChanges();
            }

            return(Ok());
        }
示例#16
0
        public async Task <IActionResult> Post(string familyId, [FromBody] FamilyViewModel familyVm)
        {
            var context = GetUserContext();

            familyVm.FamilyId = familyId;

            var family = ToFamily(familyVm, context.ChurchId);
            var result = await DataRepository.UpdateFamily(family);

            return(result ? Ok() : StatusCode((int)HttpStatusCode.InternalServerError));
        }
示例#17
0
        public IActionResult AddFamilyMember(FamilyViewModel model)
        {
            if (!ModelState.IsValid || User.Identity?.Name == null)
            {
                return(RedirectToAction("Error"));
            }

            var currentEmail = User.Identity.Name;

            _userRepository.AddRelationship(currentEmail, model.Email);
            return(RedirectToAction("Family"));
        }
示例#18
0
 private Family ToFamily(FamilyViewModel familyVm, string churchId)
 {
     return(new Family
     {
         ChurchId = churchId,
         FamilyId = familyVm.FamilyId,
         Address = familyVm.Address,
         PhotoUrl = familyVm.PhotoUrl,
         HomeParish = familyVm.HomeParish,
         Members = familyVm.Members
     });
 }
        public void AddFamilyToForm(int formId, FamilyViewModel family)
        {
            Mapper.Reset();
            var form = dataBase.Forms.Get(formId);

            // конфигурирование AutoMapper. Отображение объекта FamilyViewModel на объект Family. Тип слева - тип источника, а тип справа - тип назначения
            Mapper.Initialize(cfg => cfg.CreateMap <FamilyViewModel, Family>());
            var fam = Mapper.Map <Family>(family);

            form.Families.Add(fam);
            dataBase.Save();
        }
示例#20
0
        public async Task <IActionResult> Index(FamilyViewModel model)
        {
            ModelState.Clear();
            CalendarUser user = await _userManager.GetUserAsync(User);

            Guid guidID = Guid.Parse(model.SelectedFamily);
            var  family = await _familyService.GetFamilyById(guidID);

            model = await UpdateModel(user, family, model);

            return(View(model));
        }
示例#21
0
        public ActionResult <FamilyViewModel> Update(int id, FamilyViewModel family)
        {
            if (ModelState.IsValid && family.Id == id)
            {
                var updatedFamily = this._familyRepository.GetItemById(family.Id, null);
                _mapper.Map(family, updatedFamily);
                this._familyRepository.Update(updatedFamily);

                return(Ok(family));
            }

            return(BadRequest(family));
        }
示例#22
0
        public async Task <IActionResult> Post([FromBody] FamilyViewModel familyVm)
        {
            var context = GetUserContext();

            var family = ToFamily(familyVm, context.ChurchId);
            var result = await DataRepository.AddFamily(family);

            if (result)
            {
                _logger.LogInformation($"Creating new family Succed using {context}");
                return(Created($"/api/families/{family.FamilyId}", ""));
            }
            return(BadRequest());
        }
示例#23
0
        public async Task <IActionResult> Index([FromRoute] int id)
        {
            try
            {
                var familyViewModel = new FamilyViewModel();
                familyViewModel.Patient = await _patientViewModelService.GetPatientWithFamily(id);

                // ViewBag.Data = familyViewModel.Patient.Siblings;
                return(View(familyViewModel));
            }
            catch (Exception exp)
            {
                throw (exp);
            }
        }
示例#24
0
        protected override object GetUpdateDialogView()
        {
            if (ViewModel is FamiliesViewModel viewModel && viewModel.SelectedModel != null)
            {
                var familyVm = new FamilyViewModel()
                {
                    Id   = viewModel.SelectedModel.Id,
                    Name = viewModel.SelectedModel.Name
                };

                return(new FamilyDialog("Изменить", familyVm));
            }

            return(null);
        }
        public async Task <ActionResult <FamilyViewModel> > CreateAsync(FamilyViewModel familyView)
        {
            if (ModelState.IsValid)
            {
                var family = _mapper.Map <FamilyViewModel, Family>(familyView);

                var createdFamily = await _service.CreateAsync(family);

                familyView.Id = createdFamily.Id;

                return(CreatedAtAction(nameof(GetByIdAsync), new { id = familyView.Id }, familyView));
            }

            return(BadRequest(familyView));
        }
示例#26
0
        public IActionResult Index()
        {
            if (authProvider.IsLoggedIn)
            {
                FamilyViewModel fvm = new FamilyViewModel();
                fvm.CurrentUser = authProvider.GetCurrentUser();
                fvm.Family      = familyDAL.GetFamily(fvm.CurrentUser.FamilyId);

                return(View(fvm));
            }
            else
            {
                return(View("Login", "Account"));
            }
        }
示例#27
0
        public async Task IndexPOST_ReturnsBadRequestResult_WhenModelStateIsInvalid()
        {
            var mockService = new Mock <IPatientViewModelService>();

            mockService.Setup(service => service.UpdatePatientWithFamily(It.IsAny <FamilyPatientViewModel>()));
            var controller = new FamilyController(mockService.Object);

            controller.ModelState.AddModelError("Name", "Required");
            var familyViewModel = new FamilyViewModel();

            var result = await controller.Index(familyViewModel);

            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.IsType <SerializableError>(badRequestResult.Value);
        }
示例#28
0
        public async Task <IActionResult> Create(FamilyViewModel model)
        {
            if (ModelState.IsValid)
            {
                CalendarUser user = await _userManager.GetUserAsync(User);

                model.Family.FamilyMembers.Add(user);
                model.Family.CreatorID = user.Id;
                model.Family.ID        = Guid.NewGuid();
                Family family = model.Family;
                await _familyService.WriteToDB(family);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
示例#29
0
 public ActionResult AddFamily()
 {
     if (Session["CurrentUser"] != null)
     {
         ViewBag.CountryList = clsBusinessLogic.GetCountryList();
         ViewBag.StateList   = new List <State>();
         ViewBag.CityList    = new List <City>();
         var candidate = new FamilyViewModel();
         candidate.FamilyMembers.Add(new FamilyMember());
         return(View(candidate));
     }
     else
     {
         Session["LastPage"] = "AddCandidate";
         return(RedirectToAction("SignIn", "Account"));
     }
 }
示例#30
0
        public IHttpActionResult Create([FromBody] FamilyViewModel family)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _familyService.Create(_mapper.Map <Family>(family));

            return(Ok(new
            {
                name = family.Name,
                familyId = family.FamilyId,
                description = family.Description,
                goal = family.Goal
            }));
        }
        public ActionResult FamilyView(FamilyViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.FamilyList = db.family;

                var newFamily = new Family
                {
                    Name   = model.Name,
                    Points = 0,
                    Amount = 0
                };
                db.family.Add(newFamily);
                db.SaveChanges();
            }
            return(View(model));
        }
        public ActionResult SaveFamilyDetails(FamilyViewModel familyviewModel, List <ChildViewModel> childViewModel)
        {
            bool Status   = false;
            int  parentId = 0;

            try
            {
                parentId = familyServices.Insert(familyviewModel, childViewModel);

                Status = parentId > 0;
            }
            catch (Exception ex)
            {
                Status = false;
                Logger.Log(ex.Message.ToString(), "Family", "SaveFamilyDetails");
            }
            return(Json(new { Status, parentId }, JsonRequestBehavior.AllowGet));
        }
示例#33
0
 public static void UpdateFamily(this Family family, FamilyViewModel familyVm)
 {
     family.FamilyName = familyVm.FamilyName;
     family.FirstRegisteredDate = familyVm.FirstRegisteredDate;
     family.Notes = familyVm.Notes;
     family.EthnicityID = familyVm.EthnicityID;
     if (familyVm.DiagnosisID == 0)
     {
         familyVm.DiagnosisID = null;
     }
     if (familyVm.DiagnosisSubTypeID == 0)
     {
         familyVm.DiagnosisSubTypeID = null;
     }
     family.DiagnosisID = familyVm.DiagnosisID;
     family.DiagnosisSubTypeId = familyVm.DiagnosisSubTypeID;
     family.Deleted = familyVm.Deleted;
     Random rnd = new Random();
     int number = rnd.Next(1000, 1000000);
     if (family.FamilyIdentifier == null)
     {
         family.FamilyIdentifier = "F" + number.ToString();
     }
 }
示例#34
0
        public HttpResponseMessage Update(HttpRequestMessage request, FamilyViewModel family)
        {
            return CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest,
                        ModelState.Keys.SelectMany(k => ModelState[k].Errors)
                              .Select(m => m.ErrorMessage).ToArray());
                }
                else
                {
                    Family _family = _familyRepository.GetSingle(family.ID);
                    _family.UpdateFamily(family);

                    _unitOfWork.Commit();

                    response = request.CreateResponse(HttpStatusCode.OK);
                }

                return response;
            });
        }