예제 #1
0
        public async Task <ActionResult> ChangePassword(IndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await UserManager.ChangePasswordAsync(Guid.Parse(User.Identity.GetUserId()), model.OldPassword, model.NewPassword);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(Guid.Parse(User.Identity.GetUserId()));

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }

                TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateSuccess("Your password has been changed.");
                return(View("Index", new IndexViewModel()));
            }

            AddErrors(result);
            return(View("Index", model));
        }
예제 #2
0
        public ActionConfirmation SaveOrUpdateComentario(RespuestaComentario respuestaComentario)
        {
            if (!respuestaComentario.IsValid())
            {
                return(ActionConfirmation.CreateFailure("respuesta no es válida"));
            }

            try
            {
                _comentarioRepository.SaveOrUpdate(respuestaComentario);
                _comentarioRepository.DbContext.CommitChanges();

                var confirmation = ActionConfirmation.CreateSuccess("Respuesta " + respuestaComentario.Id + " guardada!");
                confirmation.Value = respuestaComentario;

                return(confirmation);
            }
            catch (Exception exception)
            {
                _eventLogService.AddException(exception.Message,
                                              exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, respuestaComentario.ActualizadoPor, EventSource.Sistema);

                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #3
0
        /// <summary>
        /// Saves the or update.
        /// </summary>
        /// <param name="logItem">The log item.</param>
        /// <returns></returns>
        public ActionConfirmation SaveOrUpdate(LogItem logItem)
        {
            try
            {
                if (logItem.IsValid())
                {
                    this._logItemRepository.SaveOrUpdate(logItem);
                    _logItemRepository.DbContext.CommitChanges();


                    ActionConfirmation confirmation = ActionConfirmation.CreateSuccess("Log Added!");
                    confirmation.Value = logItem;

                    return(confirmation);
                }
                else
                {
                    this._logItemRepository.DbContext.RollbackTransaction();

                    return
                        (ActionConfirmation.CreateFailure(
                             "The log item could not be saved due to missing or invalid information"));
                }
            }
            catch (Exception exception)
            {
                return(ActionConfirmation.CreateFailure("Cannot insert into the log > " + exception.Message));
            }
        }
예제 #4
0
        public ActionConfirmation SaveOrUpdate(Evaluacion evaluacion)
        {
            if (!evaluacion.IsValid())
            {
                return(ActionConfirmation.CreateFailure("evaluación no es válida"));
            }

            try
            {
                _evaluacionRepository.SaveOrUpdate(evaluacion);
                _evaluacionRepository.DbContext.CommitChanges();

                var confirmation = ActionConfirmation.CreateSuccess("Evaluacion " + evaluacion.Id + " guardada!");
                confirmation.Value = evaluacion;

                return(confirmation);
            }
            catch (Exception exception)
            {
                _eventLogService.AddException(exception.Message,
                                              exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, evaluacion.ActualizadoPor, EventSource.Sistema);

                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #5
0
        public ActionConfirmation Queue(EmailQueueItem item)
        {
            try
            {
                if (item.IsValid())
                {
                    _queueRepository.SaveOrUpdate(item);
                    _queueRepository.DbContext.CommitChanges();

                    var saveOrUpdateConfirmation = ActionConfirmation.CreateSuccess("The emails were successfully queued.");
                    saveOrUpdateConfirmation.Value = item;

                    return(saveOrUpdateConfirmation);
                }
                else
                {
                    _queueRepository.DbContext.RollbackTransaction();

                    return
                        (ActionConfirmation.CreateFailure(
                             "The item could not be queued due to missing or invalid information"));
                }
            }
            catch (Exception exception)
            {
                return
                    (ActionConfirmation.CreateFailure(
                         "The email could not be saved due to missing or invalid information > " + exception.Message));
            }
        }
예제 #6
0
        public ActionConfirmation QueueSendingFailure(int itemId, int failureInterval, int maxNumberOfTries)
        {
            var emailToQueue = _queueRepository.Get(itemId);

            if (emailToQueue != null)
            {
                try
                {
                    _queueRepository.QueueSendingFailure(emailToQueue, failureInterval, maxNumberOfTries);

                    var confirmation =
                        ActionConfirmation.CreateSuccess(
                            "The email was successfully queued for sending failure");
                    confirmation.Value = emailToQueue;

                    return(confirmation);
                }
                catch (Exception)
                {
                    return
                        (ActionConfirmation.CreateFailure(
                             "A problem was encountered preventing the email queue sending failure"));
                }
            }

            return
                (ActionConfirmation.CreateFailure(
                     "The email could not be found to queue failure. It may already have been deleted"));
        }
예제 #7
0
        public ActionConfirmation SaveOrUpdate(Setting dbSetting)
        {
            if (dbSetting.IsValid())
            {
                try
                {
                    _settingRepository.SaveOrUpdate(dbSetting);
                    _settingRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccess("setting saved ok!"));
                }
                catch (System.Exception exception)
                {
                    _eventLogService.AddException(exception.Message,
                                                  exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, dbSetting.UpdatedBy, EventSource.Sistema);

                    var confirmation = ActionConfirmation.CreateFailure("setting not saved | " + exception.ToString());
                    return(confirmation);
                }
            }
            else
            {
                return(ActionConfirmation.CreateFailure("setting is not valid!"));
            }
        }
예제 #8
0
        public ActionConfirmation Delete(int itemId)
        {
            var emailToDelete = _queueRepository.Get(itemId);

            if (emailToDelete != null)
            {
                try
                {
                    _queueRepository.Delete(emailToDelete);
                    _queueRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccess("The email was successfully deleted."));
                }
                catch
                {
                    return
                        (ActionConfirmation.CreateFailure(
                             "A problem was encountered preventing the email from being deleted. " +
                             "Another item likely depends on this email"));
                }
            }

            return
                (ActionConfirmation.CreateFailure(
                     "The email could not be found to deletion. It may already have been deleted"));
        }
예제 #9
0
        public ActionConfirmation DeleteJefeArea(Guid id)
        {
            var item = _jefeAreaRepository.Get(id);

            if (item == null)
            {
                return(ActionConfirmation.CreateFailure("item no existe"));
            }

            try
            {
                if (item.Locales.Any())
                {
                    foreach (var local in item.Locales)
                    {
                        _localService.Delete(local.Id);
                    }
                }

                _jefeAreaRepository.Delete(item.Id);
                _jefeAreaRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("Delete OK (" + item.Nombre + ")"));
            }
            catch (Exception exception)
            {
                _eventLogService.AddException(exception.Message,
                                              exception.StackTrace, EventCategory.EliminarObjeto.ToString(), exception, item.ActualizadoPor, EventSource.Sistema);

                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #10
0
        public ActionResult SaveCover(string coverPatternName, HttpPostedFileBase image, bool deleteImageCover = false)
        {
            var  userId = this.CurrentUserSessionContext().UserId;
            User user   = _userService.FindById(userId);

            if (deleteImageCover)
            {
                if (user.CoverFile != null)
                {
                    user.CoverFile.Version++;
                    user.CoverFile = null;
                }
            }
            else if (image != null)
            {
                File file = _fileService.Create(userId, image.FileName, image.ContentType, image.ContentLength, image.InputStream);
                user.CoverFile = file;
            }
            else
            {
                user.CoverPatternName = coverPatternName;
            }

            _userService.Update(user);
            _unitOfWork.Commit();

            TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateSuccess("Your cover has been saved.");
            EditProfileViewModel model = _usersViewModelService.CreateEditProfileViewModel(userId);

            return(View("Edit", model));
        }
예제 #11
0
        public ActionConfirmation SaveOrUpdateImagen(ImagenLocal imagenLocal)
        {
            if (!imagenLocal.IsValid())
            {
                return(ActionConfirmation.CreateFailure("imagenLocal no es válida"));
            }

            try
            {
                _imagenRepository.SaveOrUpdate(imagenLocal);
                _imagenRepository.DbContext.CommitChanges();

                var confirmation = ActionConfirmation.CreateSuccess("Respuesta " + imagenLocal.Id + " guardada!");
                confirmation.Value = imagenLocal;

                return(confirmation);
            }
            catch (Exception exception)
            {
                _eventLogService.AddException(exception.Message,
                                              exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, imagenLocal.ActualizadoPor, EventSource.Sistema);

                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #12
0
        public ActionResult ChangeAccountState(bool isAccountEnabled)
        {
            if (isAccountEnabled)
            {
                TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateSuccess("Your account has been enabled.");
            }
            else
            {
                TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateSuccess("Your account has been disabled.");
            }

            return(View("Index", new IndexViewModel()));
        }
예제 #13
0
        public ActionConfirmation Delete(IdentityUser user)
        {
            try
            {
                _userRepository.Delete(user);
                _userRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("user deleted"));
            }
            catch (Exception exception)
            {
                return(ActionConfirmation.CreateFailure("error > " + exception.Message));
            }
        }
예제 #14
0
        public ActionConfirmation SaveOrUpdateUserProfile(PerfilUsuario perfilUsuario)
        {
            try
            {
                _userProfileRepository.SaveOrUpdate(perfilUsuario);
                _userProfileRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("saved ok"));
            }
            catch (System.Exception exception)
            {
                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #15
0
        public ActionConfirmation Delete(IdentityRole role)
        {
            try
            {
                _roleRepository.Delete(role);
                _roleRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("role deleted"));
            }
            catch (Exception exception)
            {
                return(ActionConfirmation.CreateFailure("error > " + exception.Message));
            }
        }
        public ActionResult Create(SpeechViewModel model)
        {
            var     currentUserId = this.CurrentUserSessionContext().UserId;
            Message message       = _messageService.CreateSpeech(model.Mind, model.Speech, currentUserId);

            if (message != null)
            {
                _unitOfWork.Commit();
                TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateSuccess("Your speech has been created.");
                return(RedirectToActionPermanent("Edit", new { @id = message.Id }));
            }

            TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateError("Your speech has not been created. Try again.");
            return(View(model));
        }
예제 #17
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (!IsRecaptchaValid())
            {
                ModelState.AddModelError("", "Are you sure that you are human?");
            }

            if (ModelState.IsValid)
            {
                var language = _languageService.FindByCode(model.Language);

                var user = new User {
                    UserName         = model.UserName,
                    Email            = model.Email,
                    LastName         = model.LastName,
                    FirstName        = model.FirstName,
                    Language         = language,
                    GravatarHash     = model.Email.Trim().ToLower().CalculateMd5Hash(),
                    CreationDate     = DateTime.UtcNow,
                    Version          = 1,
                    CoverPatternName = GetCoverPatternName()
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                    if (Request.Url != null)
                    {
                        var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                        _emailService.SendEmail(user.Email, user.FirstName, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    }

                    TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateSuccess("Your account has been created. Check email for further instructions.");
                    return(RedirectToAction("Index", "Home"));
                }

                AddErrors(result);
            }

            model.Languages          = _languageService.FindAll().ToList();
            model.RecaptchaPublicKey = _settingService.RecaptchaPublicKey;

            return(View(model));
        }
예제 #18
0
        public ActionConfirmation SaveOrUpdateRegion(Region region)
        {
            if (!region.IsValid())
            {
                return(ActionConfirmation.CreateFailure("not valid"));
            }

            try
            {
                _regionRepository.SaveOrUpdate(region);
                _regionRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("saved ok"));
            }
            catch (Exception exception)
            {
                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #19
0
        public ActionConfirmation SaveOrUpdateGroup(Grupo grupo)
        {
            if (!grupo.IsValid())
            {
                return(ActionConfirmation.CreateFailure("not valid"));
            }

            try
            {
                _groupRepository.SaveOrUpdate(grupo);
                _groupRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("saved ok"));
            }
            catch (System.Exception exception)
            {
                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #20
0
        public ActionConfirmation SaveOrUpdate(Project project)
        {
            if (!project.IsValid())
            {
                return(ActionConfirmation.CreateFailure("proyecto no valido"));
            }

            try
            {
                _projectRepository.SaveOrUpdate(project);
                _projectRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("saved ok"));
            }
            catch (System.Exception exception)
            {
                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #21
0
        public ActionConfirmation SaveOrUpdateMember(ProjectMember member)
        {
            if (!member.IsValid())
            {
                return(ActionConfirmation.CreateFailure("miembro no válido"));
            }

            try
            {
                _memberRepository.SaveOrUpdate(member);
                _memberRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("member created"));
            }
            catch (System.Exception exception)
            {
                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #22
0
        public ActionConfirmation SaveOrUpdateUser(Usuario usuario)
        {
            if (!usuario.IsValid())
            {
                return(ActionConfirmation.CreateFailure("invalid object"));
            }

            try
            {
                _userRepository.SaveOrUpdate(usuario);
                _userRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("ok"));
            }
            catch (System.Exception exception)
            {
                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #23
0
        public ActionConfirmation SaveOrUpdate(IdentityUser user)
        {
            if (user.IsValid())
            {
                try
                {
                    _userRepository.SaveOrUpdate(user);
                    _userRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccess("user saved"));
                }
                catch (Exception exception)
                {
                    return(ActionConfirmation.CreateFailure("error > " + exception.Message));
                }
            }
            else
            {
                return(ActionConfirmation.CreateFailure("user is not valid"));
            }
        }
예제 #24
0
        public ActionConfirmation SaveOrUpdate(Estado estado)
        {
            if (!estado.IsValid())
            {
                return(ActionConfirmation.CreateFailure("not valid!"));
            }

            try
            {
                _statusRepository.SaveOrUpdate(estado);
                _statusRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("saved ok"));
            }
            catch (Exception exception)
            {
                _eventLogService.AddException(exception.Message,
                                              exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, estado.ActualizadoPor, EventSource.Sistema);
                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #25
0
        public ActionConfirmation SaveOrUpdate(IdentityRole role)
        {
            if (role.IsValid())
            {
                try
                {
                    _roleRepository.SaveOrUpdate(role);
                    _roleRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccess("role saved"));
                }
                catch (Exception exception)
                {
                    return(ActionConfirmation.CreateFailure("error > " + exception.Message));
                }
            }
            else
            {
                return(ActionConfirmation.CreateFailure("role is not valid"));
            }
        }
        public ActionResult Edit(SpeechViewModel model)
        {
            var currentUserId = this.CurrentUserSessionContext().UserId;

            if (!_messageService.HasRightToMessage(currentUserId, model.MessageId))
            {
                return(new HttpAccessDeniedResult());
            }

            Message message = _messageService.UpdateSpeech(model.MessageId, model.Mind, model.Speech);

            if (message != null)
            {
                _unitOfWork.Commit();
                TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateSuccess("Your speech has been saved.");
                return(RedirectToActionPermanent("Edit", new { @id = message.Id }));
            }

            TempData[ActionConfirmation.TempDataKey] = ActionConfirmation.CreateError("Your speech has not been saved. Try again.");
            return(View(model));
        }
예제 #27
0
        /// <summary>
        ///   Adds the specified activity type.
        /// </summary>
        /// <param name = "activityType">Type of the activity.</param>
        /// <param name = "eventType">Type of the event.</param>
        /// <param name = "message">The message.</param>
        /// <param name = "objectId">The object id.</param>
        /// <param name = "objectType">Type of the object.</param>
        /// <param name = "username">The username.</param>
        /// <returns></returns>
        public ActionConfirmation Add(
            string activityType,
            EventType eventType,
            string message,
            string objectId,
            string objectType,
            string username)
        {
            var logItem = new LogItem
            {
                Category           = EventCategory.Actividad.ToString(),
                EventDate          = DateTime.Now,
                IsVisible          = true,
                Message            = activityType,
                MessageDescription = message,
                Username           = username,
                ObjectId           = objectId,
                ObjectType         = objectType,
                EventType          = (short)eventType,
                Source             = EventSource.Sistema.ToString()
            };

            ActionConfirmation confirmation;

            try
            {
                _eventLogService.Write(logItem);
                confirmation = ActionConfirmation.CreateSuccess("Activity Added");
            }
            catch (Exception exception)
            {
                _eventLogService.AddException(
                    exception.Message, exception.ToString(), EventCategory.NoDefinida.ToString(), exception);

                confirmation =
                    ActionConfirmation.CreateFailure("Activity cannot be added > " + exception.Message);
            }

            return(confirmation);
        }
예제 #28
0
        public ActionConfirmation Delete(Guid id)
        {
            var status = Get(id);

            if (status == null)
            {
                return(ActionConfirmation.CreateFailure("Status no existe"));
            }

            try
            {
                _statusRepository.Delete(status);
                return(ActionConfirmation.CreateSuccess("status borrado!"));
            }
            catch (System.Exception exception)
            {
                _eventLogService.AddException(exception.Message, exception.StackTrace, EventCategory.EliminarObjeto.ToString(), exception, "", EventSource.Sistema);

                var confirmation = ActionConfirmation.CreateFailure("status no eliminado | " + exception);
                return(confirmation);
            }
        }
예제 #29
0
        public ActionConfirmation SaveOrUpdateGeneral(GerenteGeneral gerenteGeneral)
        {
            if (!gerenteGeneral.IsValid())
            {
                return(ActionConfirmation.CreateFailure("item no es válido"));
            }

            try
            {
                _generalRepository.SaveOrUpdate(gerenteGeneral);
                _generalRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("saved ok"));
            }
            catch (Exception exception)
            {
                _eventLogService.AddException(exception.Message,
                                              exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, gerenteGeneral.ActualizadoPor, EventSource.Sistema);

                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }
예제 #30
0
        public ActionConfirmation SaveOrUpdateSistema(Sistema item)
        {
            if (!item.IsValid())
            {
                return(ActionConfirmation.CreateFailure("objeto no es válida"));
            }

            try
            {
                _sistemaRepository.SaveOrUpdate(item);
                _sistemaRepository.DbContext.CommitChanges();

                return(ActionConfirmation.CreateSuccess("saved ok"));
            }
            catch (Exception exception)
            {
                _eventLogService.AddException(exception.Message,
                                              exception.StackTrace, EventCategory.GuardarObjeto.ToString(), exception, item.ActualizadoPor, EventSource.Sistema);

                return(ActionConfirmation.CreateFailure(exception.ToString()));
            }
        }