public ActionResult Create(Volunteer volunteer, IFormFile image)
 {
     try
     {
         if (UniversalFunctions.ContainsSpecialChar(JsonConvert.SerializeObject(volunteer)))
         {
             ModelState.AddModelError("Cannot contain semi-colons", "Cannot contain semi-colons");
         }
         ModelState.Remove("Birthdate");
         ModelState.Remove("HourCount");
         ModelState.Remove("CIEliberat");
         if (ModelState.IsValid)
         {
             volunteer._id       = Guid.NewGuid().ToString();
             volunteer.Birthdate = volunteer.Birthdate.AddHours(5);
             volunteer.Image     = UniversalFunctions.Addimage(image);
             volunteerManager.AddVolunteerToDB(volunteer);
             return(RedirectToAction("Index"));
         }
         else
         {
             ViewBag.containsspecialchar = UniversalFunctions.ContainsSpecialChar(JsonConvert.SerializeObject(volunteer));
             return(View());
         }
     }
     catch
     {
         return(RedirectToAction("Localserver", "Home"));
     }
 }
Пример #2
0
        public ActionResult Edit(string id, Beneficiary beneficiary, IFormFile image)
        {
            try
            {
                if (UniversalFunctions.ContainsSpecialChar(JsonConvert.SerializeObject(beneficiary)))
                {
                    ModelState.AddModelError("Cannot contain semi-colons", "Cannot contain semi-colons");
                }
                ModelState.Remove("Contract.RegistrationDate");
                ModelState.Remove("Contract.ExpirationDate");
                ModelState.Remove("Marca.IdAplication");
                ModelState.Remove("CI.ExpirationDateCI");
                ModelState.Remove("Marca.IdContract");
                ModelState.Remove("Marca.IdInvestigation");
                ModelState.Remove("NumberOfPortions");
                ModelState.Remove("LastTimeActiv");
                ModelState.Remove("Personalinfo.Birthdate");
                ModelState.Remove("CI.ICExpirationDate");
                if (ModelState.IsValid)
                {
                    if (image != null)
                    {
                        beneficiary.Image = UniversalFunctions.Addimage(image);
                    }
                    else
                    {
                        Beneficiary b = beneficiaryManager.GetOneBeneficiary(id);
                        beneficiary.Image = b.Image;
                    }
                    List <ModifiedIDs> modifiedidlist = modifiedDocumentManager.GetListOfModifications();
                    string             modifiedids    = JsonConvert.SerializeObject(modifiedidlist);
                    if (!modifiedids.Contains(id))
                    {
                        Beneficiary currentbeneficiary   = beneficiaryManager.GetOneBeneficiary(id);
                        string      currentbenefasstring = JsonConvert.SerializeObject(currentbeneficiary);
                        auxiliaryDBManager.AddDocumenttoDB(currentbenefasstring);
                    }
                    beneficiary.PersonalInfo.Birthdate = beneficiary.PersonalInfo.Birthdate.AddHours(5);
                    beneficiaryManager.UpdateABeneficiary(beneficiary, id);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.id = id;
                    bool containsspecialchar = true;
                    return(RedirectToAction("Edit", new { id, containsspecialchar }));
                }
            }
            catch
            {
                return(RedirectToAction("Localserver", "Home"));
            }
        }
        public ActionResult Edit(string id, Volunteer volunteer, IFormFile image)
        {
            try
            {
                if (UniversalFunctions.ContainsSpecialChar(JsonConvert.SerializeObject(volunteer)))
                {
                    ModelState.AddModelError("Cannot contain semi-colons", "Cannot contain semi-colons");
                }
                ModelState.Remove("Birthdate");
                ModelState.Remove("HourCount");
                ModelState.Remove("CIEliberat");
                if (ModelState.IsValid)
                {
                    if (image != null)
                    {
                        volunteer.Image = UniversalFunctions.Addimage(image);
                    }
                    else
                    {
                        Volunteer v = volunteerManager.GetOneVolunteer(id);
                        volunteer.Image = v.Image;
                    }
                    volunteer.Birthdate = volunteer.Birthdate.AddHours(5);

                    List <ModifiedIDs> modifiedidlist = modifiedDocumentManager.GetListOfModifications();
                    string             modifiedids    = JsonConvert.SerializeObject(modifiedidlist);
                    if (!modifiedids.Contains(id))
                    {
                        Volunteer currentvol         = volunteerManager.GetOneVolunteer(id);
                        string    currentvolasstring = JsonConvert.SerializeObject(currentvol);
                        auxiliaryDBManager.AddDocumenttoDB(currentvolasstring);
                    }
                    volunteerManager.UpdateAVolunteer(volunteer, id);

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.id = id;
                    bool containsspecialchar = true;
                    return(RedirectToAction("Edit", new { id, containsspecialchar }));
                }
            }
            catch
            {
                return(RedirectToAction("Localserver", "Home"));
            }
        }
Пример #4
0
        public ActionResult Create(Beneficiary beneficiary, IFormFile image)
        {
            try
            {
                if (UniversalFunctions.ContainsSpecialChar(JsonConvert.SerializeObject(beneficiary)))
                {
                    ModelState.AddModelError("Cannot contain semi-colons", "Cannot contain semi-colons");
                }
                ModelState.Remove("CI.ExpirationDateCI");
                ModelState.Remove("Contract.RegistrationDate");
                ModelState.Remove("Contract.ExpirationDate");
                ModelState.Remove("Marca.IdAplication");
                ModelState.Remove("CI.CIEliberat");
                ModelState.Remove("Marca.IdContract");
                ModelState.Remove("Marca.IdInvestigation");
                ModelState.Remove("NumberOfPortions");
                ModelState.Remove("LastTimeActiv");
                ModelState.Remove("Personalinfo.Birthdate");
                ModelState.Remove("CI.ICExpirationDate");

                if (ModelState.IsValid)
                {
                    beneficiary._id = Guid.NewGuid().ToString();
                    beneficiary.PersonalInfo.Birthdate = beneficiary.PersonalInfo.Birthdate.AddHours(5);
                    beneficiary.Image = UniversalFunctions.Addimage(image);
                    beneficiaryManager.AddBeneficiaryToDB(beneficiary);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.containsspecialchar = UniversalFunctions.ContainsSpecialChar(JsonConvert.SerializeObject(beneficiary));
                    return(View());
                }
            }
            catch
            {
                return(RedirectToAction("Localserver", "Home"));
            }
        }