public ActionResult New(AccessViewModel model, string accessLevel)
        {
            if (!isAuthenticated() || !loggedUser.isAdmin)
                return new HttpUnauthorizedResult();
            else
            {
                if (ModelState.IsValid)
                {
                    if (!new User().emailExists(model.Email))
                    {
                        Common common = new Common();
                        string newPassword = common.generatePassword(6);
                        bool emailSent = common.sendEmail(model.Email, string.Format("Seu acesso foi criado no Agenda SUD\n\nEmail: {0}\nSenha: {1}\n\nAgenda SUD\nhttp://lds.toughland.com", model.Email, newPassword), "Agenda SUD - Acesso Criado");
                        Result result = new User().addUser(model.Email, newPassword, loggedUser.Unit, (accessLevel == "A"));

                        if (emailSent && result.Success)
                            return RedirectToAction("Index");
                        else
                        {
                            ModelState.AddModelError("", "Ocorreu um erro ao criar novo acesso");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Endereço de email já está sendo utilizado por outro usuário");
                    }
                }
                return View(model);
            }
        }
Exemple #2
0
 public int getMemberPriesthood(int memberId)
 {
     int reference = 0;
     foreach (List<string> data in database.retrieveData("select reference from bakeappdb.lds_priesthood where member_id = @member_id order by id asc", memberId))
     {
         reference = new Common().convertNumber(data[0]);
     }
     return reference;
 }
 public ActionResult Get(string date)
 {
     if (!isAuthenticated() || !loggedUser.isAdmin)
         return new HttpUnauthorizedResult();
     else
     {
         DateTime meetingDate = new Common().convertDate(date.Replace("/", "-"), true);
         Memo memo = new Memo();
         memo.loadData(meetingDate, loggedUser.Unit);
         return Json(memo, JsonRequestBehavior.AllowGet);
     }
 }
        public ActionResult Save(int id, string date, int conductedBy, int presidedBy, string recognitions,
            int firstHymn, int firstPrayer, string stake, int stakeFlag, string ward, int wardFlag, int sacramentalHymn,
            int speaker1, int speaker2, int speaker3, int speaker4, int speaker5, string theme1, string theme2,
            string theme3, string theme4, string theme5, int intermediateHymn, int pianist,
            int conductor, string otherSubjects, int lastHymn, int lastPrayer)
        {
            if (!isAuthenticated() || !loggedUser.isAdmin)
                return new HttpUnauthorizedResult();
            else
            {
                DateTime meetingDate = new Common().convertDate(date.Replace("/", "-"), true);

                Memo memo = new Memo();
                memo.id = id;
                memo.date = meetingDate;
                memo.conductedBy = conductedBy;
                memo.presidedBy = presidedBy;
                memo.recognitions = recognitions;
                memo.openingHymn = firstHymn;
                memo.firstPrayer = firstPrayer;
                memo.stake = stake;
                memo.stakeFlag = stakeFlag;
                memo.ward = ward;
                memo.wardFlag = wardFlag;
                memo.sacramentalHymn = sacramentalHymn;
                memo.speaker1 = speaker1;
                memo.speaker2 = speaker2;
                memo.speaker3 = speaker3;
                memo.speaker4 = speaker4;
                memo.speaker5 = speaker5;
                memo.speaker1Theme = theme1;
                memo.speaker2Theme = theme2;
                memo.speaker3Theme = theme3;
                memo.speaker4Theme = theme4;
                memo.speaker5Theme = theme5;
                memo.intermediateHymn = intermediateHymn;
                memo.pianistBy = pianist;
                memo.hymnConductedBy = conductor;
                memo.otherSubjects = otherSubjects;
                memo.lastHymn = lastHymn;
                memo.lastPrayer = lastPrayer;

                return Json(memo.updateOrAdd(loggedUser.Unit), JsonRequestBehavior.AllowGet);
            }
        }
 public ActionResult ForgotPassword(string email)
 {
     User user = new User().getUser(email.ToLower());
     if (user.Id == 0)
         return RedirectToAction("Feedback", new { message = "Usuário não encontrado" });
     else
     {
         Common common = new Common();
         string newPassword = common.generatePassword(6);
         Result result = user.updateUser(user.Id, email.ToLower(), newPassword);
         if (result.Success && common.sendEmail(email, string.Format("Sua nova senha é\n\n{0}\n\nAgenda SUD\nhttp://lds.toughland.com", newPassword), "Agenda SUD - Nova senha"))
         {
             return RedirectToAction("Feedback", new { message = "Uma nova senha foi enviada para seu endereço de email" });
         }
         else
         {
             return RedirectToAction("Feedback", new { message = "Erro ao enviar nova senha" });
         }
     }
 }
        public ActionResult Index(HttpPostedFileBase file)
        {
            if (!isAuthenticated() || !loggedUser.isAdmin)
                return new HttpUnauthorizedResult();
            else
            {
                if (file != null && file.ContentLength > 0 && (file.ContentType == "text/csv" || file.ContentType == "application/vnd.ms-excel"))
                {
                    var fileName = new Common().generatePassword(20) + DateTime.Now.Ticks;
                    var path = Path.Combine(Server.MapPath("~/App_Data"), fileName);
                    file.SaveAs(path);

                    Result result = new Result(false);

                    using (var reader = new StreamReader(path, System.Text.Encoding.GetEncoding("ISO-8859-1")))
                    {
                        result = new BatchCommand().execute(reader, loggedUser.Unit);
                    }

                    System.IO.File.Delete(path);

                    if (result.Success)
                    {
                        return RedirectToAction("Success");
                    }
                    else
                    {
                        ModelState.AddModelError("", "Erro ao ler arquivo. Por favor verifique o arquivo novamente");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Erro ao ler arquivo. Por favor verifique o arquivo novamente");
                }
                return View();
            }
        }