Beispiel #1
0
        public ActionResult Edit(TimesPADs time, HttpPostedFileBase fotoUpload)
        {
            Validacao(time);
            if (ModelState.IsValid)
            {
                time.DataCadastro = DateTime.Now;
                time.Excluido     = false;

                #region uploads

                if (fotoUpload != null)
                {
                    var fileOriginal = Server.MapPath(string.Format(pathOriginal, time.Id));
                    var path100x100  = Server.MapPath(string.Format(pathLogo100x100, time.Id));

                    time.Logo = Utils.SaveFileBase(fileOriginal, fotoUpload);
                    Utils.resizeImageAndSave3(Path.Combine(fileOriginal, time.Logo), 100, 100, path100x100);
                }

                db.Entry(time).State = EntityState.Modified;
                db.SaveChanges();
                #endregion

                GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Edicao, time.Id);
                return(RedirectToAction("Details", new { id = time.Id }));
            }
            return(View(time));
        }
Beispiel #2
0
        public ActionResult Create(TimesPADs time, HttpPostedFileBase logo)
        {
            Validacao(time);
            if (logo == null)
            {
                ModelState.AddModelError("Logo", "O time deve ter um logo.");
            }
            if (ModelState.IsValid)
            {
                time.Excluido     = false;
                time.DataCadastro = DateTime.Now;

                db.TimesPADs.Add(time);

                if (db.SaveChanges() > 0)
                {
                    #region uploads
                    var fileOriginal = Server.MapPath(string.Format(pathOriginal, time.Id));
                    var path100x100  = Server.MapPath(string.Format(pathLogo100x100, time.Id));

                    time.Logo = Utils.SaveFileBase(fileOriginal, logo);
                    Utils.resizeImageAndSave3(Path.Combine(fileOriginal, time.Logo), 100, 100, path100x100);

                    db.Entry(time).State = EntityState.Modified;
                    db.SaveChanges();
                    #endregion
                }

                GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Insercao, time.Id);
                return(RedirectToAction("Index"));
            }
            return(View(time));
        }
Beispiel #3
0
        public ActionResult Details(int id = 0)
        {
            TimesPADs time = db.TimesPADs.Find(id);

            if (time == null)
            {
                return(HttpNotFound());
            }
            return(View(time));
        }
Beispiel #4
0
 private void Validacao(TimesPADs time)
 {
     if (string.IsNullOrWhiteSpace(time.Nome))
     {
         ModelState.AddModelError("Nome", "O Nome deve ser preenchido.");
     }
     else if (time.Nome.Length > 150)
     {
         ModelState.AddModelError("Nome", "O Nome não deve ter mais do que 150 caracteres.");
     }
 }
Beispiel #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            TimesPADs time = db.TimesPADs.Find(id);

            time.Excluido        = true;
            db.Entry(time).State = EntityState.Modified;


            db.SaveChanges();
            GerenciaLogs.saveLog(ref db, WebSecurity.GetUserId(User.Identity.Name), areaADM, TipoAcesso.Exclusao, time.Id);
            return(RedirectToAction("Index"));
        }