コード例 #1
0
ファイル: ParentController.cs プロジェクト: erickdc/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));
        }
コード例 #2
0
        private void AddUsersToPersonalNotification(Notification notificationIdentity)
        {
            var notificationParentId =
                _studentRepository.Filter(x => x.Id == notificationIdentity.IdGradeAreaUserGeneralSelected).Where(x => x.Tutor1 != null).Select(x => x.Tutor1).FirstOrDefault();

            if (notificationParentId != null)
            {
                var parents = _parentRepository.GetById(notificationParentId.Id);
                var user    = parents.MyUser;
                if (user != null)
                {
                    notificationIdentity.Users.Add(user);
                    SendEmail.SendEmailToUsers(notificationIdentity.Users.ToList(),
                                               "Se ha creado una notificacion en la cual usted ha sido incluido.Mensaje: " +
                                               notificationIdentity.Message, "Notificacion creada");
                }
            }
        }
コード例 #3
0
        public ActionResult Edit(StudentEditModel modelStudent)
        {
            var validImageTypes = new []
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (modelStudent.FilePicture != null && modelStudent.FilePicture.ContentLength > 0)
            {
                if (!validImageTypes.Contains(modelStudent.FilePicture.ContentType))
                {
                    ModelState.AddModelError("FilePicture", "Por favor seleccione entre una imagen GIF, JPG o PNG");
                }
            }
            var myStudent = _studentRepository.GetById(modelStudent.Id);

            try
            {
                byte[] fileBytes = null;
                if (modelStudent.FilePicture != null)
                {
                    using (var binaryReader = new BinaryReader(modelStudent.FilePicture.InputStream))
                    {
                        fileBytes = binaryReader.ReadBytes(modelStudent.FilePicture.ContentLength);
                    }
                }
                if (modelStudent.Tutor1 == null)
                {
                    modelStudent.Tutor1 = myStudent.Tutor1;
                }
                if (modelStudent.Tutor2 == null)
                {
                    modelStudent.Tutor2 = myStudent.Tutor2;
                }
                var studentModel = Mapper.Map <StudentEditModel, Student>(modelStudent);
                studentModel.MyGender = Implement.Utilities.DefineGender(modelStudent.MyGender);
                modelStudent.Photo    = null;
                studentModel.Photo    = fileBytes ?? myStudent.Photo;
                studentModel.MyUser   = _parentRepository.GetById(modelStudent.Tutor1.Id).MyUser;
                myStudent             = _studentRepository.UpdateStudentFromStudentEditModel(studentModel, myStudent);
                const string title   = "Estudiante Actualizado";
                var          content = "El estudiante " + myStudent.FullName + " ha sido actualizado exitosamente.";
                _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.InformationMessage);
                return(RedirectToAction("Index"));
            }
            catch
            {
                modelStudent.MyGender    = myStudent.MyGender.ToString("G").Substring(0, 1);
                modelStudent.FirstParent = myStudent.Tutor1.Id;
                modelStudent.Tutor1      = myStudent.Tutor1;
                modelStudent.Tutor2      = myStudent.Tutor2;
                if (myStudent.Tutor2 != null)
                {
                    modelStudent.SecondParent = myStudent.Tutor2.Id;
                }
                ViewBag.Tutor1Id = new SelectList(_parentRepository.Query(x => x), "Id", "FullName",
                                                  modelStudent.Tutor1.Id);
                if (modelStudent.Tutor2 == null)
                {
                    modelStudent.Tutor2 = new Parent();
                }
                ViewBag.Tutor2Id = new SelectList(_parentRepository.Query(x => x), "Id", "FullName",
                                                  modelStudent.Tutor2.Id);
                return(View(modelStudent));
            }
        }