コード例 #1
0
        public JsonResult ProcReservarMatImovel(TipoReservaMatImovel TipoReserva, long IdPrenotacao, string NumMatricula)
        {
            bool                   resp          = false;
            string                 message       = string.Empty;
            DtoReservaImovel       reservaImovel = new DtoReservaImovel();
            List <ApplicationUser> listaUsrSist  = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().Users.OrderBy(u => u.UserName).ToList();

            try
            {
                using (AppServiceAtos appServiceAtos = new AppServiceAtos(this.UfwCartNew, this.IdCtaAcessoSist))
                {
                    appServiceAtos.ListaUsuariosSistema = listaUsrSist;
                    reservaImovel = appServiceAtos.ProcReservarMatImovel(TipoReserva, IdPrenotacao, NumMatricula, this.UsuarioAtual.Id);
                }

                resp    = reservaImovel.Resposta;
                message = reservaImovel.Msg;
            }
            catch (Exception ex)
            {
                TypeInfo t = this.GetType().GetTypeInfo();
                IOFunctions.GerarLogErro(t, ex);

                resp    = false;
                message = "Falha, ProcReservarMatImovel [" + ex.Message + "]";
            }

            var resultado = new
            {
                resposta = resp,
                operacao = reservaImovel.Operacao,
                tipoMsg  = reservaImovel.TipoMsg,
                msg      = message,
                Reserva  = reservaImovel
            };

            return(Json(resultado));
        }
コード例 #2
0
        public DtoReservaImovel ProcReservarMatImovel(TipoReservaMatImovel TipoReserva, long IdPrenotacao, string NumMatricula, string IdUsuario)
        {
            DtoReservaImovel reserva = new DtoReservaImovel();
            DtoDadosImovel   Imovel  = null;
            PrenotacaoImovel PreImo  = null;

            reserva.Resposta = true;

            PreImo = this.UfwCartNew.Repositories.GenericRepository <PrenotacaoImovel>().GetWhere(p =>
                                                                                                  (p.IdPrenotacao == IdPrenotacao) &&
                                                                                                  (p.NumMatricula == NumMatricula) &&
                                                                                                  (p.IdUsuario != IdUsuario)).FirstOrDefault();

            if (PreImo == null)
            {
                Imovel = this.GetDadosImovel(IdPrenotacao, NumMatricula);

                if (Imovel != null)
                {
                    reserva.Imovel = Imovel;

                    switch (TipoReserva)
                    {
                    case TipoReservaMatImovel.Reservar:

                        if (reserva.Resposta)
                        {
                            PreImo = this.UfwCartNew.Repositories.GenericRepository <PrenotacaoImovel>().GetWhere(p =>
                                                                                                                  (p.IdPrenotacao == IdPrenotacao) &&
                                                                                                                  (p.NumMatricula == NumMatricula) &&
                                                                                                                  (p.IdUsuario == IdUsuario)).FirstOrDefault();

                            if (PreImo != null)
                            {
                                reserva.TipoMsg  = TipoMsgResposta.warning;
                                reserva.Msg      = string.Format("Você já tinha reservado a matrícula: {0}", PreImo.NumMatricula);
                                reserva.Resposta = true;
                            }
                            else
                            {
                                PreImo = new PrenotacaoImovel();
                                PreImo.IdPrenotacao = IdPrenotacao;
                                PreImo.NumMatricula = NumMatricula;
                                PreImo.IdUsuario    = IdUsuario;
                                reserva.Operacao    = DataBaseOperacoes.insert;
                                this.UfwCartNew.Repositories.GenericRepository <PrenotacaoImovel>().Add(PreImo);
                                this.UfwCartNew.SaveChanges();

                                reserva.TipoMsg = TipoMsgResposta.ok;
                                reserva.Msg     = string.Format("Matrícula {0} reservada com sucesso!", NumMatricula);
                            }
                        }
                        break;

                    case TipoReservaMatImovel.Liberar:

                        PreImo = this.UfwCartNew.Repositories.GenericRepository <PrenotacaoImovel>().GetWhere(p =>
                                                                                                              (p.IdPrenotacao == IdPrenotacao) &&
                                                                                                              (p.NumMatricula == NumMatricula) &&
                                                                                                              (p.IdUsuario == IdUsuario)).FirstOrDefault();

                        if (PreImo == null)
                        {
                            reserva.TipoMsg  = TipoMsgResposta.warning;
                            reserva.Msg      = string.Format("Matrícula {0} já está liberada!", PreImo.NumMatricula);
                            reserva.Resposta = false;
                        }
                        else
                        {
                            this.UfwCartNew.Repositories.GenericRepository <PrenotacaoImovel>().Remove(PreImo);
                            this.UfwCartNew.SaveChanges();
                            reserva.Operacao = DataBaseOperacoes.delete;
                            reserva.TipoMsg  = TipoMsgResposta.ok;
                            reserva.Msg      = string.Format("Matrícula {0} liberada com sucesso!", NumMatricula);;
                        }
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    reserva.Resposta = false;
                    reserva.TipoMsg  = TipoMsgResposta.error;
                    reserva.Msg      = "Imóvel não localizado";
                }
            }
            else
            {
                reserva.TipoMsg = TipoMsgResposta.error;

                if (this.listaUsrSist != null)
                {
                    var usr = this.listaUsrSist.Where(u => u.IdUsuario == PreImo.IdUsuario).FirstOrDefault();
                    reserva.Msg = string.Format("Imóvel já reservado pelo usuário: {0}!", "[" + usr.LoginName + "] " + usr.Nome);
                }
                else
                {
                    reserva.Msg = "Imóvel já reservado por outro usuário";
                }
                reserva.Resposta = false;
            }
            return(reserva);
        }