Ejemplo n.º 1
0
        public IPostResponse GetCurrentLoans([FromContent] LoanHistoryRequest Request)
        {
            var db = new SqliteDB();
            //TODO: Check for email..
            var loans = db.GetCurrentLoans();

            if (loans == null || loans.Count == 0)
            {
                return(new PostResponse(PostResponse.ResponseStatus.Conflict, null, new ResponseData {
                    Code = 1, Message = "No loans found"
                }));
            }

            var returnList = new List <LoanHistoryRespose>();

            foreach (var loan in loans)
            {
                if (loan.ExpireDate > DateTime.Now.Ticks)
                {
                    if (loan.Email == Request.Email)
                    {
                        var dev = db.GetDevice(new DeviceList {
                            SerialNumber = loan.Mac
                        });

                        returnList.Add(new LoanHistoryRespose {
                            ExpireDate = DateTime.FromBinary(loan.ExpireDate).ToString(), ExpireDateTick = loan.ExpireDate, SerialNumber = loan.Mac, Username = loan.GeneratedUsername, Password = loan.GeneratedPassword, Host = dev.Host, Model = dev.Model
                        });
                    }
                }
            }
            if (returnList.Count > 0)
            {
                return(new PostResponse(PostResponse.ResponseStatus.Created, null, returnList));
            }
            return(new PostResponse(PostResponse.ResponseStatus.Conflict, null, new ResponseData {
                Code = 1, Message = "No loans found"
            }));
        }