Ejemplo n.º 1
0
 public GenericActionResult <UserCredit> UpdateUserCredit(UserCreditModel userCreditModel)
 {
     try
     {
         UserCredit credit = context.UserCredits.Find(userCreditModel.Id);
         credit.Production = userCreditModel.Production;
         credit.TalentId   = userCreditModel.TalentId;
         context.SaveChanges();
         return(new GenericActionResult <UserCredit>(true, "User credit updated successfully.", credit));
     }
     catch (Exception) { return(new GenericActionResult <UserCredit>("Failed to update credit, please try again or contact the administrator.")); }
 }
 public UserCreditResponseModel ToUserCreditResponseModel(UserCredit userCredit)
 {
     return(new UserCreditResponseModel
     {
         Talent = context.Talents.Find(userCredit.TalentId),
         UserId = userCredit.UserId,
         Production = userCredit.Production,
         Id = userCredit.Id,
         IsDeleted = userCredit.IsDeleted,
         DateCreated = userCredit.DateCreated
     });
 }
        // GET: UserCredits/Edit/Player1 (example)
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserCredit userCredit = _db.UserCredits.Find(id);

            if (userCredit == null)
            {
                return(HttpNotFound());
            }
            return(View(userCredit));
        }
Ejemplo n.º 4
0
 public GenericActionResult <UserCredit> SaveUserCredit(UserCreditModel userCreditModel)
 {
     try
     {
         var userCredit = new UserCredit
         {
             Production  = userCreditModel.Production,
             TalentId    = userCreditModel.TalentId,
             UserId      = userCreditModel.UserId,
             IsDeleted   = false,
             DateCreated = DateTime.Now
         };
         context.UserCredits.Add(userCredit);
         context.SaveChanges();
         return(new GenericActionResult <UserCredit>(true, "User credit saved successfully.", userCredit));
     }
     catch (Exception) { return(new GenericActionResult <UserCredit>("Failed to save credit, please try again or contact the administrator.")); }
 }
Ejemplo n.º 5
0
        public async Task <ActionResult <int> > AddCredit(int UserId, [FromBody] Credit credit)
        {
            if (ModelState.IsValid && credit != null && UserId > 0)
            {
                User user = _context.User.Where(u => u.Id == UserId).FirstOrDefault <User>();
                Safe safe = _context.Safe.FirstOrDefault <Safe>();
                if (user == null)
                {
                    return(NotFound("User not foound"));
                }

                credit.DateTime = DateTime.Now; // get current date and time;

                UserCredit userCredit = new UserCredit()
                {
                    Credit = credit,
                    User   = user
                };
                _context.Credits.Add(credit);
                _context.UserCredit.Add(userCredit);

                //update requestsTable
                Request request = new Request()
                {
                    User        = user,
                    Type        = "Deposit",
                    isCompleted = true,
                    Amount      = credit.Value,
                    Response    = "Deposit successful"
                };
                _context.Request.Add(request);
                await _context.SaveChangesAsync();

                int withdrawals = (int)new WithdrawalsController(_context).GetUserTotalWithdrawal(UserId).Result.Value;
                int deposits    = (int)GetUserTotalCredit(UserId).Result.Value;
                int balance     = deposits - withdrawals;
                return(balance);
            }
            else
            {
                return(BadRequest());
            }
        }
        public ActionResult Create([Bind(Include = "UserId,Credits")] UserCredit userCredit)
        {
            TempData["UserExists"] = false;


            var userExists = _db.UserCredits.Find(userCredit.UserId);

            if (userExists != null)
            {
                TempData["UserExists"] = true;
                return(RedirectToAction("Create"));
            }


            if (ModelState.IsValid)
            {
                _db.UserCredits.Add(userCredit);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(userCredit));
        }
        private void mnuTabCredit_Click(object sender, RoutedEventArgs e)
        {
            UserCredit userCredit = new UserCredit(accountId);

            AddTab(userCredit);
        }
Ejemplo n.º 8
0
        public override string ToString()
        {
            CultureInfo swedish = new CultureInfo("sv-SE");

            swedish = (CultureInfo)swedish.Clone();
            swedish.NumberFormat.CurrencyPositivePattern = 3;
            swedish.NumberFormat.CurrencyNegativePattern = 3;
            return(string.Format("Unique Items on sale: {0} , Total Items: {1}, Machine Bank: {2}, Buyer Credit: {3} \n",
                                 machineItems.Count, GetTotalMachineItems(), machineBank.ToString("C0", swedish), UserCredit.ToString("C0", swedish)));
        }
Ejemplo n.º 9
0
 public static ResponceModel Control(string method, string credit, int?id, int?subid, string time, string content, string pic)
 {
     try
     {
         if (credit == null)
         {
             return(ResponceModel.GetInstanceInvalid());
         }
         else if (credit == "")
         {
             return(new ResponceModel(403, "凭证为空"));
         }
         else
         {
             if (UserCredit.CheckUser(credit, out string username))
             {
                 if (method == "add")
                 {
                     if (content == null)
                     {
                         return(ResponceModel.GetInstanceInvalid());
                     }
                     else
                     {
                         return(Add(username, content, pic));
                     }
                 }
                 else if (method == "update")
                 {
                     if (time == null)
                     {
                         return(ResponceModel.GetInstanceInvalid());
                     }
                     else
                     {
                         return(Update(time));
                     }
                 }
                 else if (method == "addcomment")
                 {
                     if (id == null || content == null)
                     {
                         return(ResponceModel.GetInstanceInvalid());
                     }
                     else
                     {
                         return(AddComment(username, id.Value, content));
                     }
                 }
                 else if (method == "change")
                 {
                     if (id == null || content == null)
                     {
                         return(ResponceModel.GetInstanceInvalid());
                     }
                     else
                     {
                         return(Change(username, id.Value, content, pic));
                     }
                 }
                 else if (method == "delete")
                 {
                     if (id == null)
                     {
                         return(ResponceModel.GetInstanceInvalid());
                     }
                     else
                     {
                         return(Delete(username, id.Value));
                     }
                 }
                 else if (method == "deletecomment")
                 {
                     if (id == null || subid == null)
                     {
                         return(ResponceModel.GetInstanceInvalid());
                     }
                     else
                     {
                         return(DeleteCommnet(username, (int)id, (int)subid));
                     }
                 }
                 else
                 {
                     return(ResponceModel.GetInstanceInvalid());
                 }
             }
             else
             {
                 return(new ResponceModel(403, "无效的凭证"));
             }
         }
     }
     catch (Exception ex)
     {
         return(ResponceModel.GetInstanceError(ex));
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取课表,此方法用于与外部进行交互,依赖<see cref="UserCredit"/>,<see cref="TermTime"/>,<see cref="UserInfoSql"/>。
        /// </summary>
        /// <param name="credit"></param>
        /// <returns></returns>
        internal static ResponceModel GetCourse(string credit, int year, int term)
        {
            try
            {
                if (UserCredit.CheckUser(credit, out string username))
                {
                    UserInfoSql userInfo = new UserInfoSql(username);
                    if (userInfo.TryQuery())
                    {
                        //if (userInfo.courseserver == "ZJUT")
                        //{
                        if (UserInfo.GetBindInfo(username, "jh").state != 0)
                        {
                            //说明你绑定过正方账号。
                            if (UserInfo.GetBindInfo(username, "zfedu").state != 0)
                            {
                                if (JhUser.CheckUser(userInfo.jhpid, userInfo.pwbind_jh).code == 200)
                                {
                                    //TermTimeUni time = TermTime.Get();
                                    //TermTimeUni time = new TermTimeUni(2019,3,)
                                    var result = GetZfCourse(userInfo.jhpid, userInfo.pwbind_zfedu, year, term);
                                    if (result.code == 200)
                                    {
                                        var data = (List <CourseUni>)result.data;

                                        if (data.Count > 0)
                                        {
                                            foreach (var item in data)
                                            {
                                                if (!item.Exists())
                                                {
                                                    item.Add();
                                                }
                                                userInfo.Linkedcourse = data.Map((m) => m.courseid);

                                                userInfo.UpdateLinkedCourse();
                                            }
                                        }


                                        //if (data.Count > 0)
                                        //{
                                        //    foreach (var item in data)
                                        //    {
                                        //        //在这里我们假设课表信息从不改变,虽然说绝大多数情况下是这样。
                                        //        if (!item.Exists())
                                        //        {
                                        //            item.Add();
                                        //        }
                                        //        userInfo.Linkedcourse = data.Map((m) => m.courseid).ToList();
                                        //        userInfo.UpdateLinkedCourse();
                                        //    }
                                        //}

                                        return(new ResponceModel(200, "获取课表成功", data));
                                    }
                                    else
                                    {
                                        return(new ResponceModel(403, "请重新绑定正方"));
                                    }
                                }
                                else
                                {
                                    return(new ResponceModel(403, "请重新绑定正方"));
                                }
                            }
                            else
                            {
                                //SOLVED BUG 这里曾导致未绑定账号但任然显示重新绑定的错误提示信息。
                                return(new ResponceModel(403, "你还没有绑定正方"));
                            }
                        }
                        else
                        {
                            return(new ResponceModel(403, "请重新绑定精弘账号"));
                        }
                        //}
                        //else
                        //{
                        //    return new ResponceModel(500, "暂不支持这个提供商");
                        //}
                    }
                    else
                    {
                        return(new ResponceModel(403, "请绑定精弘账号"));
                    }
                }
                else
                {
                    return(new ResponceModel(403, "自动登录失败,请重新登录"));
                }
            }
            catch (Exception ex)
            {
                return(ResponceModel.GetInstanceError(ex));
            }
        }
 public JsonResult Post(string method, string username, string password, string nickname, string devicetype, string newpassword, string credit)
 {
     return(UserCredit.Control(method, username, password, nickname, devicetype, newpassword, credit));
 }