コード例 #1
0
ファイル: ParentController.cs プロジェクト: armejiaf/Mhotivo
 public ActionResult DetailsEdit(ParentEditModel modelParent)
 {
     var myParent = _parentRepository.GetById(modelParent.Id);
     var parentModel = Mapper.Map<ParentEditModel, Parent>(modelParent);
     _parentRepository.UpdateParentFromParentEditModel(parentModel, myParent);
     const string title = "Padre o Tutor Actualizado";
     var content = "El Padre o Tutor " + myParent.FullName + " ha sido actualizado exitosamente.";
     _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.InformationMessage);
     return RedirectToAction("Details/" + modelParent.Id);
 }
コード例 #2
0
ファイル: ParentController.cs プロジェクト: armejiaf/Mhotivo
 public ActionResult Edit(ParentEditModel modelParent)
 {
     var validImageTypes = new []
     {
         "image/gif",
         "image/jpeg",
         "image/pjpeg",
         "image/png"
     };
     if (modelParent.UploadPhoto != null && modelParent.UploadPhoto.ContentLength > 0)
     {
         if (!validImageTypes.Contains(modelParent.UploadPhoto.ContentType))
         {
             ModelState.AddModelError("UploadPhoto", "Por favor seleccione entre una imagen GIF, JPG o PNG");
         }
     }
     if (ModelState.IsValid)
     {
         try
         {
             byte[] fileBytes = null;
             if (modelParent.UploadPhoto != null)
             {
                 using (var binaryReader = new BinaryReader(modelParent.UploadPhoto.InputStream))
                 {
                     fileBytes = binaryReader.ReadBytes(modelParent.UploadPhoto.ContentLength);
                 }
             }
             var myParent = _parentRepository.GetById(modelParent.Id);
             var parentModel = Mapper.Map<ParentEditModel, Parent>(modelParent);
             parentModel.Photo = null;
             parentModel.Photo = fileBytes ?? myParent.Photo;
             _parentRepository.UpdateParentFromParentEditModel(parentModel, myParent);
             const string title = "Padre o Tutor Actualizado";
             var content = "El Padre o Tutor " + myParent.FullName + " ha sido actualizado exitosamente.";
             _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.InformationMessage);
             return RedirectToAction("Index");
         }
         catch
         {
             return View(modelParent);
         }
     }
     return View(modelParent);
 }
コード例 #3
0
ファイル: ParentRepository.cs プロジェクト: armejiaf/Mhotivo
 public Parent UpdateParentFromParentEditModel(ParentEditModel parentEditModel, Parent parent)
 {
     parent.FirstName = parentEditModel.FirstName;
     parent.LastName = parentEditModel.LastName;
     parent.FullName = (parentEditModel.FirstName + " " + parentEditModel.LastName).Trim();
     parent.Country = parentEditModel.Country;
     parent.IdNumber = parentEditModel.IdNumber;
     parent.BirthDate = parentEditModel.BirthDate;
     parent.Gender = Utilities.IsMasculino(parentEditModel.Gender);
     parent.Nationality = parentEditModel.Nationality;
     parent.State = parentEditModel.State;
     parent.City = parentEditModel.City;
     parent.Address = parentEditModel.Address;
     return Update(parent);
 }