Beispiel #1
0
        public ActionResult talao(Int16 id = 0, Int16 id2 = 0, string id3 = "")//repreid, talaoid, inicio
        {
            var   model   = new TalaoModelView();
            Int16 repreid = Domain.Util.valida.getRepresentanteID(User.Identity.Name);

            if (!string.IsNullOrEmpty(id3))
            {
                ViewBag.erro = id3.Replace("-", " ");
            }

            if (id != 0 & id2 != 0)
            {
                //busca as informações para edição
                model = ServiceTalao.GetTalaoId(id2);
                model.Representantes = ServiceRepresentante.getRepresentante(id);
                model.Taloes         = GetTaloes(id);
            }
            else
            {
                model.Representantes = ServiceRepresentante.getRepresentante(repreid);
                model.Taloes         = GetTaloes(repreid);
            }

            ViewBag.repreid = repreid;

            return(View(model));
        }
Beispiel #2
0
        public ActionResult TalaoItens(Int16 id = 0, Int16 id2 = 0, string id3 = "")//repreid, Talaoid, TalaoItensid
        {
            TalaoItensModelView model = new TalaoItensModelView();

            if (!string.IsNullOrEmpty(id3) & id3 != "0")
            {
                model = ServiceTalaoItens.GetTalaoItensId(Convert.ToInt16(id3));
            }

            if (id != 0 & id2 != 0)
            {
                model.Representantes    = ServiceRepresentante.getRepresentante(id);
                model.TaloesItens       = ServiceTalaoItens.GetTalaoItens(id2, id);
                model.TaloesItensStatus = ServiceTalaoItensStatus.getTalaoItensStatusCombo();
                model.Taloes            = ServiceTalao.getTalaoid(id2);
            }

            //pega o representante
            ViewBag.repre = getRepre(model.Representantes);

            //pega o Talao ini e final
            getIntervalo(model.Taloes);

            ViewBag.situacao = Domain.Util.valida.getSituacao(model.talaoitensstatusid);
            return(View(model));
        }
Beispiel #3
0
        public ActionResult talao(TalaoModelView model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Login", "Account", null));
            }

            Int16 repreid = Domain.Util.valida.getRepresentanteID(User.Identity.Name);

            if (ModelState.IsValid)
            {
                model.user   = User.Identity.Name;
                model.status = Convert.ToInt16(model.statusb);
                var msg = string.Empty;
                if (model.talaoid != 0) //update
                {
                    //busca os Taloes conforme inicio e final para fazer alteração - so pode alterar o status e a obs
                    List <Talao>   lst    = new List <Data.Entities.Talao>();
                    TalaoModelView msalvo = new TalaoModelView();
                    msalvo = ServiceTalao.GetTalaoId(model.talaoid);
                    msg    = Validatalao(msalvo);
                    if (string.IsNullOrEmpty(msg))
                    {
                        if (msalvo != null)
                        {
                            //alteracoes no pai
                            msalvo.dataalt = DateTime.Now;
                            msalvo.user    = User.Identity.Name;
                            msalvo.obs     = model.obs;
                            msalvo.status  = model.status;
                            ServiceTalao.UpdateTalao(msalvo);

                            //altera o status dos filhos
                            List <TalaoItens> lstItens = new List <TalaoItens>();
                            lstItens = ServiceTalaoItens.GetTalaoItens(model.talaoid);

                            TalaoItensModelView mitens = new TalaoItensModelView();
                            foreach (var item in lstItens)
                            {
                                mitens = new TalaoItensModelView();
                                mitens.talaoitensid       = item.talaoitensid;
                                mitens.talaoitensstatusid = item.talaoitensstatusid;
                                mitens.talaoid            = item.talaoid;
                                mitens.dataalt            = DateTime.Now;
                                mitens.dataincl           = item.DataIncl;
                                mitens.numero             = item.Numero;
                                mitens.obs             = item.Obs;
                                mitens.representanteid = item.representanteid;
                                mitens.status          = model.status;
                                mitens.user            = User.Identity.Name;
                                ServiceTalaoItens.UpdateTalaoItens(mitens);
                            }
                        }
                    }
                }
                else //insert
                {
                    string valida = Validatalao(model);
                    if (!string.IsNullOrEmpty(valida))
                    {
                        return(Redirect(Domain.Util.config.UrlSite + "Book/talao/0/0/" + valida));
                    }
                    else
                    {
                        //insere o pai
                        ServiceTalao.InsertTalao(model);
                        //insere os filhos conforme numeração informada.
                        TalaoItensModelView mitens = new TalaoItensModelView();

                        //pega o ultimo talaoid
                        model.talaoid = ServiceTalao.getTalaoMax(model.representanteid);

                        if (model.talaoid != 0)
                        {
                            for (int i = model.ini; i <= model.fin; i++)
                            {
                                mitens                    = new TalaoItensModelView();
                                mitens.numero             = i;
                                mitens.talaoid            = model.talaoid;
                                mitens.representanteid    = model.representanteid;
                                mitens.status             = 1;
                                mitens.user               = User.Identity.Name;
                                mitens.talaoitensstatusid = 1;
                                ServiceTalaoItens.InsertTalaoItens(mitens);
                            }

                            msg = "talao-inserido-com-sucesso!";
                        }
                    }
                }
                return(Redirect(Domain.Util.config.UrlSite + "Book/talao/0/0/" + msg));
            }

            ViewBag.repreid      = repreid;
            model.Representantes = ServiceRepresentante.getRepresentante(repreid);
            model.Taloes         = ServiceTalao.getTalao(repreid, false);

            return(View(model));
        }