Beispiel #1
0
        public SharedResultVM Detail(string id)
        {
            return(SharedResultVM.Try(vm =>
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(SharedEnum.RTag.invalid);
                }
                else
                {
                    var ctype = Application.EnumService.ConnectionType.GuffRecord.ToString();

                    var uinfo = Apps.LoginService.Get(HttpContext);

                    var query = from a in db.GuffRecord
                                join b in db.UserInfo on a.Uid equals b.UserId
                                join c in db.UserConnection.Where(x => x.UconnTargetType == ctype && x.UconnAction == 1 && x.Uid == uinfo.UserId) on a.GrId equals c.UconnTargetId into cg
                                from c1 in cg.DefaultIfEmpty()
                                where a.GrId == id
                                select new
                    {
                        a,
                        UconnTargetId = c1 == null ? null : c1.UconnTargetId,
                        b.Nickname
                    };
                    var qm = query.FirstOrDefault();
                    if (qm == null)
                    {
                        vm.Set(SharedEnum.RTag.invalid);
                    }
                    else
                    {
                        if (qm.a.GrOpen == 1 || uinfo.UserId == qm.a.Uid)
                        {
                            // 阅读 +1
                            qm.a.GrReadNum += 1;
                            db.Update(qm.a);
                            db.SaveChanges();

                            qm.a.Spare1 = string.IsNullOrEmpty(qm.UconnTargetId) ? "" : "laud";
                            qm.a.Spare2 = (uinfo.UserId == qm.a.Uid) ? "owner" : "";
                            qm.a.Spare3 = qm.Nickname;

                            vm.Data = qm.a;

                            vm.Set(SharedEnum.RTag.success);
                        }
                        else
                        {
                            vm.Set(SharedEnum.RTag.unauthorized);
                        }
                    }
                }

                return vm;
            }));
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id_Venta,Codigo_Factura,Nombre_Cliente,Fecha,Total,Id_Tienda")] Ventas ventas)
        {
            if (id != ventas.Id_Venta)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ventas);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VentasExists(ventas.Id_Venta))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(ventas));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id_Categoria,Nombre")] Categorias categorias)
        {
            if (id != categorias.Id_Categoria)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(categorias);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoriasExists(categorias.Id_Categoria))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(categorias));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id_Producto,Nombre,Precio,Cantidad,Fecha_Vencimiento,Id_Categoria")] Productos productos)
        {
            if (id != productos.Id_Producto)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(productos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductosExists(productos.Id_Producto))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(productos));
        }
Beispiel #5
0
        public void IncreaseMessageCount(string userId)
        {
            var user = context.Users.Where(u => u.UserInfo == userId).FirstOrDefault();

            user.MessageCount++;
            context.Update(user);
        }
        public async Task <IActionResult> Edit(Guid id, Curso curso)
        {
            if (id != curso.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(curso);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CursoExists(curso.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProfessorId"] = new SelectList(_context.Set <Professor>(), "Id", "Nome", curso.ProfessorId);
            return(View(curso));
        }
Beispiel #7
0
        public async Task <IActionResult> Edit(int id, [Bind("Id_Tienda,Nombre,Encargado,Contacto,Direccion")] Tiendas tiendas)
        {
            if (id != tiendas.Id_Tienda)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tiendas);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TiendasExists(tiendas.Id_Tienda))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tiendas));
        }
Beispiel #8
0
        public async Task <IActionResult> Edit(Guid id, Professor professor)
        {
            if (id != professor.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(professor);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfessorExists(professor.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(professor));
        }
Beispiel #9
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Nome,Valor,Id")] Procedimento procedimento)
        {
            if (id != procedimento.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(procedimento);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProcedimentoExists(procedimento.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(procedimento));
        }
 public void Update(T Entitie)
 {
     using (var banco = new ContextBase(_OptionsBuilder.Options))
     {
         banco.Update(Entitie);
         banco.SaveChanges();
     };
 }
Beispiel #11
0
 public T Update(T entity)
 {
     using (var banco = new ContextBase(_OptionsBuilder.Options))
     {
         banco.Update(entity);
         banco.SaveChanges();
     };
     return(entity);
 }
        public async Task <bool> ConfirmaCompraCarrinhoUsuario(string userId)
        {
            try
            {
                using (var banco = new ContextBase(_optionsBuilder))
                {
                    var compraUsuario = new CompraUsuario();

                    compraUsuario.ListaProdutos = new List <Produto>();

                    var produtosCarrinhoUsuario = await(from p in banco.Produto
                                                        join c in banco.CompraUsuario on p.Id equals c.IdProduto
                                                        where c.UserId.Equals(userId) && c.Estado == EnumEstadoCompra.Produto_Carrinho
                                                        select c).AsNoTracking().ToListAsync();

                    produtosCarrinhoUsuario.ForEach(p =>
                    {
                        compraUsuario.IdCompra = p.IdCompra;
                        p.Estado = EnumEstadoCompra.Produto_Comprado;
                    });

                    var compra = await banco.Compra.AsNoTracking().FirstOrDefaultAsync(c => c.Id == compraUsuario.IdCompra);

                    if (compra != null)
                    {
                        compra.Estado = EnumEstadoCompra.Produto_Comprado;
                    }

                    banco.Update(compra);
                    banco.UpdateRange(produtosCarrinhoUsuario);

                    await banco.SaveChangesAsync();

                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #13
0
        public ActionResultVM Detail(string id)
        {
            var vm = new ActionResultVM();

            try
            {
                if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else
                {
                    var ctype = Application.EnumService.ConnectionType.GuffRecord.ToString();

                    var uinfo = new Application.UserAuthService(HttpContext).Get();

                    var query = from a in db.GuffRecord
                                join b in db.UserInfo on a.Uid equals b.UserId
                                join c in db.UserConnection.Where(x => x.UconnTargetType == ctype && x.UconnAction == 1 && x.Uid == uinfo.UserId) on a.GrId equals c.UconnTargetId into cg
                                from c1 in cg.DefaultIfEmpty()
                                where a.GrId == id
                                select new
                    {
                        a,
                        c1.UconnTargetId,
                        b.Nickname
                    };
                    var qm = query.FirstOrDefault();
                    if (qm == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        if (qm.a.GrOpen == 1 || uinfo.UserId == qm.a.Uid)
                        {
                            // 阅读 +1
                            qm.a.GrReadNum += 1;
                            db.Update(qm.a);
                            db.SaveChanges();

                            qm.a.Spare1 = string.IsNullOrEmpty(qm.UconnTargetId) ? "" : "laud";
                            qm.a.Spare2 = (uinfo.UserId == qm.a.Uid) ? "owner" : "";
                            qm.a.Spare3 = qm.Nickname;

                            vm.Data = qm.a;

                            vm.Set(ARTag.success);
                        }
                        else
                        {
                            vm.Set(ARTag.unauthorized);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Filters.FilterConfigs.WriteLog(HttpContext, ex);
            }

            return(vm);
        }
Beispiel #14
0
        public ActionResultVM Connection(string type, int ac, string id)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new Func.UserAuthAid(HttpContext).Get();

                if (uinfo.UserId == 0)
                {
                    vm.Set(ARTag.unauthorized);
                }
                else if (string.IsNullOrWhiteSpace(id))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (!new List <string> {
                    "add", "cancel"
                }.Contains(type))
                {
                    vm.Set(ARTag.invalid);
                }
                else if (!new List <int> {
                    1, 2
                }.Contains(ac))
                {
                    vm.Set(ARTag.invalid);
                }
                else
                {
                    using var db = new ContextBase();
                    var currMo = db.GuffRecord.Find(id);

                    if (currMo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        var ctype = Func.EnumAid.ConnectionType.GuffRecord.ToString();
                        switch (type)
                        {
                        case "add":
                        {
                            if (db.UserConnection.Any(x => x.Uid == uinfo.UserId && x.UconnTargetType == ctype && x.UconnTargetId == id && x.UconnAction == ac))
                            {
                                vm.Set(ARTag.exist);
                            }
                            else
                            {
                                //关联记录
                                var ucmo = new Domain.UserConnection()
                                {
                                    UconnId         = Core.UniqueTo.LongId().ToString(),
                                    Uid             = uinfo.UserId,
                                    UconnTargetType = Func.EnumAid.ConnectionType.GuffRecord.ToString(),
                                    UconnTargetId   = id,
                                    UconnAction     = ac,
                                    UconnCreateTime = DateTime.Now
                                };

                                db.Add(ucmo);

                                switch (ac)
                                {
                                case 1:
                                    currMo.GrLaud += 1;
                                    break;

                                case 2:
                                    currMo.GrMark += 1;
                                    break;
                                }
                                db.Update(currMo);

                                int num = db.SaveChanges();

                                vm.Set(num > 0);
                            }
                        }
                        break;

                        case "cancel":
                        {
                            var curruc = db.UserConnection.FirstOrDefault(x => x.Uid == uinfo.UserId && x.UconnTargetType == ctype && x.UconnTargetId == id && x.UconnAction == ac);
                            if (curruc == null)
                            {
                                vm.Set(ARTag.invalid);
                            }
                            else
                            {
                                db.Remove(curruc);

                                switch (ac)
                                {
                                case 1:
                                    currMo.GrLaud -= 1;
                                    break;

                                case 2:
                                    currMo.GrMark -= 1;
                                    break;
                                }
                                db.Update(currMo);

                                int num = db.SaveChanges();

                                vm.Set(num > 0);
                            }
                        }
                        break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Core.ConsoleTo.Log(ex);
            }

            return(vm);
        }
Beispiel #15
0
        public ActionResultVM Update(Domain.GuffRecord mo)
        {
            var vm = new ActionResultVM();

            try
            {
                var uinfo = new Func.UserAuthAid(HttpContext).Get();

                if (string.IsNullOrWhiteSpace(mo.GrContent) && string.IsNullOrWhiteSpace(mo.GrImage) && string.IsNullOrWhiteSpace(mo.GrAudio) && string.IsNullOrWhiteSpace(mo.GrVideo))
                {
                    vm.code = 1;
                    vm.msg  = "内容不能为空(内容、图片、音频、视频 至少有一项有内容)";
                }
                else if (string.IsNullOrWhiteSpace(mo.GrTag))
                {
                    vm.code = 2;
                    vm.msg  = "标签不能为空";
                }
                else if (uinfo.UserId == 0)
                {
                    vm.Set(ARTag.unauthorized);
                }
                else
                {
                    using var db = new ContextBase();
                    var currMo = db.GuffRecord.Find(mo.GrId);

                    if (currMo == null)
                    {
                        vm.Set(ARTag.invalid);
                    }
                    else
                    {
                        currMo.GrTypeName  = Fast.ParsingTo.JsSafeJoin(mo.GrTypeName);
                        currMo.GrTypeValue = Fast.ParsingTo.JsSafeJoin(mo.GrTypeValue);
                        currMo.GrObject    = Fast.ParsingTo.JsSafeJoin(mo.GrObject);

                        currMo.GrContent   = mo.GrContent;
                        currMo.GrContentMd = mo.GrContentMd;

                        currMo.GrImage  = Fast.ParsingTo.JsSafeJoin(mo.GrImage);
                        currMo.GrAudio  = Fast.ParsingTo.JsSafeJoin(mo.GrAudio);
                        currMo.GrVideo  = Fast.ParsingTo.JsSafeJoin(mo.GrVideo);
                        currMo.GrFile   = Fast.ParsingTo.JsSafeJoin(mo.GrFile);
                        currMo.GrRemark = mo.GrRemark;

                        currMo.GrTag        = mo.GrTag;
                        currMo.GrUpdateTime = DateTime.Now;
                        currMo.GrOpen       = mo.GrOpen ?? 1;

                        db.Update(currMo);

                        int num = db.SaveChanges();

                        vm.data = mo.GrId;
                        vm.Set(num > 0);
                    }
                }
            }
            catch (Exception ex)
            {
                vm.Set(ex);
                Core.ConsoleTo.Log(ex);
            }

            return(vm);
        }