Esempio n. 1
0
        public async Task <ActionResult> Edit([Bind(Include = "idfamily,familynature,personcount,lastaddress_details,currentaddress_details,displacementdate,phone1,phone2,note,iduser,lastname,phone1owner,phone2owner,evaluation,formnumber,idcenter_FK,family_book_number,family_head,is_visited ,last_visit_date")] family family, int currentAddressID, int previousAddressID, int addressTypeID, int idKnowledgeCenter)
        {
            if (ModelState.IsValid)
            {
                db.Entry(family).State = EntityState.Modified;


                //List<familymanage> familymanages = db.familymanages.Where(f => f.idfamily_FK == family.idfamily).ToList();

                db.familymanages.RemoveRange(db.familymanages.Where(f => f.idfamily_FK == family.idfamily));

                familymanage currentAddress = new familymanage()
                {
                    idfamily_FK     = family.idfamily,
                    idmanagelist_FK = currentAddressID,
                    eval            = "Current",
                    family          = family,
                    managelist      = db.managelists.SingleOrDefault(ml => ml.idmanagelist == currentAddressID)
                };
                db.familymanages.Add(currentAddress);

                familymanage previousAddress = new familymanage()
                {
                    idfamily_FK     = family.idfamily,
                    idmanagelist_FK = previousAddressID,
                    eval            = "Previous",
                    family          = family,
                    managelist      = db.managelists.SingleOrDefault(ml => ml.idmanagelist == previousAddressID)
                };
                db.familymanages.Add(previousAddress);

                familymanage addressType = new familymanage()
                {
                    idfamily_FK     = family.idfamily,
                    idmanagelist_FK = addressTypeID,
                    eval            = "",
                    family          = family,
                    managelist      = db.managelists.SingleOrDefault(ml => ml.idmanagelist == addressTypeID)
                };
                db.familymanages.Add(addressType);

                familymanage knowledgecenter = new familymanage()
                {
                    idfamily_FK     = family.idfamily,
                    idmanagelist_FK = idKnowledgeCenter,
                    eval            = "",
                    family          = family,
                    managelist      = db.managelists.SingleOrDefault(ml => ml.idmanagelist == idKnowledgeCenter)
                };
                db.familymanages.Add(knowledgecenter);



                //foreach (managelist item in db.managelists)
                //{
                //    if (item.idmanagelist == idmangelist)
                //    {
                //        if (!item.families.Contains(family))
                //        {
                //            item.families.Add(family);
                //        }
                //    }
                //    else
                //        item.families.Remove(family);
                //}
                family.people = db.people.Where(p => p.idfamily_FK == family.idfamily).ToList();
                //string digits = "";
                Regex regex = new Regex("[0-9]{1,}");

                foreach (person p in family.people)
                {
                    //digits = new String(p.family_order_id.TakeWhile(Char.IsDigit).ToArray());
                    p.family_order_id = regex.Replace(p.family_order_id, family.family_book_number, 1);
                }



                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "families", new { id = family.idfamily }));
                //if (User.IsInRole("receptionist"))
                //{
                //    return RedirectToAction("Index");
                //}
                //else
                //{
                //    return RedirectToAction("IndexOutReach", "referalpersons", null);
                //}
            }
            ViewBag.evaluationValues   = evaluationValues;
            ViewBag.familynatureValues = familynatureValues;
            ViewBag.idmangelist        = new SelectList(db.managelists.Where(ma => ma.flag == "AT"), "idmanagelist", "name", null);
            ViewBag.sectorValues       = sectorValues;



            return(View(family));
        }
Esempio n. 2
0
        public async Task <ActionResult> Create([Bind(Include = "familynature,personcount,lastaddress_details,currentaddress_details,displacementdate,phone1,phone2,note,iduser,lastname,phone1owner,phone2owner,evaluation,family_book_number,family_head")] family family, int currentAddressID, int previousAddressID, int addressTypeID, int idKnowledgeCenter)
        {
            if (ModelState.IsValid)
            {
                family.iduser      = User.Identity.GetUserId();
                family.idcenter_FK = db.AspNetUsers.SingleOrDefault(u => u.Id == family.iduser).idcenter_FK;


                int?maxFamilyId = db.families.Where(f => f.idcenter_FK == family.idcenter_FK).Max(f => (int?)f.idfamily);
                if (maxFamilyId != null)
                {
                    family.idfamily = maxFamilyId.GetValueOrDefault() + 1;
                }
                else
                {
                    family.idfamily = db.centers.SingleOrDefault(c => c.idcenter == family.idcenter_FK).min_family_id;
                    //  family.idfamily = db.centers;
                }



                int?maxcenterform = db.families.Where(p => p.idcenter_FK == family.idcenter_FK).Max(p => p.formnumber) + 1;
                if (maxcenterform != null)
                {
                    family.formnumber = maxcenterform;
                }
                else
                {
                    family.formnumber = 1;
                }


                family.is_visited = false;


                db.families.Add(family);

                familymanage currentAddress = new familymanage()
                {
                    idfamily_FK     = family.idfamily,
                    idmanagelist_FK = currentAddressID,
                    eval            = "Current",
                    family          = family,
                    managelist      = db.managelists.SingleOrDefault(ml => ml.idmanagelist == currentAddressID)
                };
                db.familymanages.Add(currentAddress);

                familymanage previousAddress = new familymanage()
                {
                    idfamily_FK     = family.idfamily,
                    idmanagelist_FK = previousAddressID,
                    eval            = "Previous",
                    family          = family,
                    managelist      = db.managelists.SingleOrDefault(ml => ml.idmanagelist == previousAddressID)
                };
                db.familymanages.Add(previousAddress);

                familymanage addressType = new familymanage()
                {
                    idfamily_FK     = family.idfamily,
                    idmanagelist_FK = addressTypeID,
                    eval            = "",
                    family          = family,
                    managelist      = db.managelists.SingleOrDefault(ml => ml.idmanagelist == addressTypeID)
                };
                db.familymanages.Add(addressType);

                familymanage knowledgecenter = new familymanage()
                {
                    idfamily_FK     = family.idfamily,
                    idmanagelist_FK = idKnowledgeCenter,
                    family          = family,
                    eval            = "",
                    managelist      = db.managelists.SingleOrDefault(ml => ml.idmanagelist == idKnowledgeCenter)
                };
                db.familymanages.Add(knowledgecenter);

                // managelist managel = db.managelists.SingleOrDefault(ml => ml.idmanagelist == idmangelist);
                //  managel.families.Add(family);

                await db.SaveChangesAsync();

                return(RedirectToAction("Create", "people", new { id = family.idfamily }));
            }
            ViewBag.evaluationValues   = evaluationValues;
            ViewBag.familynatureValues = familynatureValues;
            //ViewBag.iduser = new SelectList(db.AspNetUsers, "Id", "Email", family.iduser);
            return(View(family));
        }