コード例 #1
0
        public ResponseModel SaveUserAccount(UserRequestModel request)
        {
            ResponseModel response = new ResponseModel();

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                try
                {
                    UserEntity userid = _context.userEntities.Where(w => w.UserName == request.UserName.Trim()).FirstOrDefault();

                    if (userid == null)
                    {
                        userid = new UserEntity()
                        {
                            UserName     = request.UserName,
                            EmailAddress = request.EmailAddress,
                            RealName     = null,
                            ModifiedDate = DateTime.Now
                        };

                        _context.userEntities.Add(userid);
                        _context.SaveChanges();

                        userid.UsersID = userid.UsersID;

                        WebpagesMembershipEntity members = _context.membershipEntities.Where(w => w.UserId == userid.UsersID).FirstOrDefault();

                        if (members == null)
                        {
                            var memData = new WebpagesMembershipEntity()
                            {
                                UserId     = userid.UsersID,
                                CreateDate = DateTime.Now,
                                PasswordFailuresSinceLastSuccess = 0,
                                Password     = request.Password,
                                PasswordSalt = "O"
                            };
                            _context.membershipEntities.Add(memData);
                            _context.SaveChanges();
                        }

                        dbContextTransaction.Commit();
                    }

                    response.data    = userid;
                    response.success = true;
                    response.message = "OK";
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                    dbContextTransaction.Rollback();
                    response.success = false;
                    response.error   = ex.Message;
                }
            }


            return(response);
        }
コード例 #2
0
        public ResponseModel AddStock(StockEntity request)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                StockEntity data = _context.stockEntities.Where(w => w.StockId == request.StockId).FirstOrDefault();

                if (data == null)
                {
                    data = new StockEntity
                    {
                        productId = request.productId,
                        amount    = request.amount
                    };

                    _context.stockEntities.Add(data);
                    _context.SaveChanges();
                }

                response.data    = data;
                response.success = true;
            }
            catch (Exception ex)
            {
                throw new NullReferenceException(ex.Message);
            }

            return(response);
        }