public async Task <IHttpActionResult> consumerUpdateJustBasicProfile(int userID, string userFirstName, string userLastName, string UserName, string userEmail, string userContactNum, DateTime consumerDateOfBirth, string consumerAddress, string maritalStatus)
        {
            //user Table:
            user    toUpdateUser = (from u in db.users where u.User_ID == userID select u).SingleOrDefault();
            DTOuser dtoUser      = new DTOuser(toUpdateUser);

            dtoUser.userFirstName     = userFirstName;
            dtoUser.userLastName      = userLastName;
            dtoUser.userName          = UserName;
            dtoUser.userEmail         = userEmail;
            dtoUser.userContactNumber = userContactNum;
            toUpdateUser = EntityMapper.updateEntity(toUpdateUser, dtoUser);
            db.Entry(toUpdateUser).State = EntityState.Modified;
            await db.SaveChangesAsync();

            consumer    toUpdCons   = (from c in db.consumers where c.User_ID == userID select c).SingleOrDefault();
            DTOconsumer dtoconsumer = new DTOconsumer(toUpdCons);

            dtoconsumer.consumerDateOfBirth = consumerDateOfBirth;
            dtoconsumer.consumerAddress     = consumerAddress;
            dtoconsumer.maritalStatus       = maritalStatus;
            toUpdCons = EntityMapper.updateEntity(toUpdCons, dtoconsumer);
            db.Entry(toUpdCons).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.OK));
        }
        public User ConvertDTOUser(DTOuser dtoUser)
        {
            List <UserRole> dtoRoles = new List <UserRole>();

            if (dtoUser.Roles != null)
            {
                foreach (var r in dtoUser.Roles)
                {
                    UserRole dtoRole = new UserRole
                    {
                        UserId = dtoUser.Id,
                        RoleId = r.Id
                    };
                    dtoRoles.Add(dtoRole);
                }
            }
            User user = new User
            {
                Id         = dtoUser.Id,
                Firstname  = dtoUser.Firstname,
                Lastname   = dtoUser.Lastname,
                Username   = dtoUser.Username,
                Password   = dtoUser.Password,
                Email      = dtoUser.Email,
                ProfileUri = dtoUser.ProfileUri,
                IsDeleted  = dtoUser.IsDeleted,
                UserRole   = dtoRoles
            };

            return(user);
        }
        // Give a user a list of his roles using a DTO user object
        public DTOuser ConvertUser(User user)
        {
            List <Role>    roles    = user.UserRole.Select(r => r.Role).ToList();
            List <DTOrole> dtoRoles = new List <DTOrole>();

            foreach (var r in roles)
            {
                DTOrole dtoRole = new DTOrole
                {
                    Id   = r.Id,
                    Name = r.Name
                };
                dtoRoles.Add(dtoRole);
            }

            DTOuser dtoUser = new DTOuser
            {
                Id         = user.Id,
                Firstname  = user.Firstname,
                Lastname   = user.Lastname,
                Username   = user.Username,
                Password   = user.Password,
                Email      = user.Email,
                ProfileUri = user.ProfileUri,
                IsDeleted  = user.IsDeleted,
                Roles      = dtoRoles
            };

            return(dtoUser);
        }
Exemple #4
0
        public static user updateEntity(user entityObjct, DTOuser dto)
        {
            if (entityObjct == null)
            {
                entityObjct = new user();
            }

            entityObjct.User_ID               = dto.User_ID;
            entityObjct.userFirstName         = dto.userFirstName;
            entityObjct.userLastName          = dto.userLastName;
            entityObjct.userName              = dto.userName;
            entityObjct.userEmail             = dto.userEmail;
            entityObjct.userContactNumber     = dto.userContactNumber;
            entityObjct.userPassword          = dto.userPassword;
            entityObjct.userIsActive          = dto.userIsActive;
            entityObjct.userType              = dto.userType;
            entityObjct.userActivationType    = dto.userActivationType;
            entityObjct.IDnumber              = dto.IDnumber;
            entityObjct.IdDocumentPath        = dto.IdDocumentPath;
            entityObjct.IdDocumentLastUpdated = dto.IdDocumentLastUpdated;
            entityObjct.timeStap              = dto.timeStap;
            entityObjct.resetPasswordKey      = dto.resetPasswordKey;
            entityObjct.blockchainAddress     = dto.blockchainAddress;
            entityObjct.otpCode               = dto.otpCode;
            entityObjct.otpRetryCount         = dto.otpRetryCount;
            entityObjct.otpExpirationTime     = dto.otpExpirationTime;
            entityObjct.otpNextAllowedTime    = dto.otpNextAllowedTime;
            entityObjct.otpRecordCreated      = dto.otpRecordCreated;

            return(entityObjct);
        }
        public async Task <IHttpActionResult> putUser(int id, DTOuser dtouser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != dtouser.User_ID)
            {
                return(BadRequest());
            }

            var putUser = db.users.Single(e => e.User_ID == id);

            db.Entry(EntityMapper.updateEntity(putUser, dtouser)).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!userExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> consumerUpdateEntireProfile(int userID, string userFirstName, string userLastName, string UserName, string userEmail, string userContactNum, DateTime consumerDateOfBirth, string consumerAddress, string maritalStatus, string homeOwnerType, string employmentStatus, Nullable <int> numDependants, string topProductsInterestedIn, Nullable <decimal> grossMonthly, Nullable <decimal> nettMonthly, Nullable <decimal> totalExpenses)
        {
            //user Table:
            user    toUpdateUser = (from u in db.users where u.User_ID == userID select u).SingleOrDefault();
            DTOuser dtoUser      = new DTOuser(toUpdateUser);

            dtoUser.userFirstName     = userFirstName;
            dtoUser.userLastName      = userLastName;
            dtoUser.userName          = UserName;
            dtoUser.userEmail         = userEmail;
            dtoUser.userContactNumber = userContactNum;
            toUpdateUser = EntityMapper.updateEntity(toUpdateUser, dtoUser);
            db.Entry(toUpdateUser).State = EntityState.Modified;
            await db.SaveChangesAsync();

            //consumer Table:
            consumer    toUpdate    = (from c in db.consumers where c.User_ID == userID select c).SingleOrDefault();
            DTOconsumer dtoConsumer = new DTOconsumer(toUpdate);

            dtoConsumer.consumerDateOfBirth = consumerDateOfBirth;
            dtoConsumer.consumerAddress     = consumerAddress;
            dtoConsumer.maritalStatus       = maritalStatus;
            dtoConsumer.homeOwnerType       = homeOwnerType;
            dtoConsumer.numDependant        = numDependants;
            dtoConsumer.topProductCategoriesInterestedIn = topProductsInterestedIn;
            dtoConsumer.grossMonthlyIncome   = grossMonthly;
            dtoConsumer.nettMonthlyIncome    = nettMonthly;
            dtoConsumer.totalMonthlyExpenses = totalExpenses;
            toUpdate = EntityMapper.updateEntity(toUpdate, dtoConsumer);
            db.Entry(toUpdate).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.OK));
        }
Exemple #7
0
        public async Task <IHttpActionResult> postConsumer(string fName, string lName, string userName, string email, string contactNum, string userPass, string IDnumber, DateTime DOB, string gender, string maritalStatus, string employmentStatus)
        {
            DTOuser newUser = await postUser(fName, lName, userName, email, contactNum, userPass, 11, IDnumber);

            if (newUser.userFirstName == null && newUser.userLastName == null)
            {
                if (newUser.userName == "-1")
                {
                    return(BadRequest("Username taken"));
                }
                else if (newUser.userEmail == "-1")
                {
                    return(BadRequest("email taken"));
                }
                else
                {
                    return(BadRequest("Invalid user"));
                }
            }

            consumer tmp = new consumer();

            tmp.User_ID             = newUser.User_ID;
            tmp.consumerDateOfBirth = DOB;
            tmp.gender           = gender;
            tmp.maritalStatus    = maritalStatus;
            tmp.employmentStatus = employmentStatus;



            db.consumers.Add(tmp);
            await db.SaveChangesAsync();

            return(Ok());
        }
        public async Task <DTOuser> Postuser(DTOuser newDTO)
        {
            user newProd = EntityMapper.updateEntity(null, newDTO);

            db.users.Add(newProd);
            await db.SaveChangesAsync();

            return(newDTO);
        }
        public async Task <IHttpActionResult> Putuser(int ID, DTOuser editedDTO)
        {
            user toUpdate = db.users.Find(ID);

            toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO);
            db.Entry(toUpdate).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> getUser(int id)
        {
            DTOuser toReturn = new DTOuser(await db.users.FindAsync(id));

            if (toReturn == null)
            {
                return(NotFound());
            }
            return(CreatedAtRoute("DefaultApi", new { id = toReturn.User_ID }, toReturn));
        }
        public async Task <IHttpActionResult> postUser(DTOuser dtoUser)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.users.Add(EntityMapper.updateEntity(null, dtoUser));
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = dtoUser.User_ID }, dtoUser));
        }
Exemple #12
0
 public DTOuser getUserFromContactNumberAndUserNameOrEmail(string userNameOrEmail, string contactNum)
 {
     //check that a matching userName/Email AND with matching contactNumber is registered, AS A CONSUMER (usertypeID 11) - not resellers.
     if (db.users.Any(u => (u.userName == userNameOrEmail || u.userEmail == userNameOrEmail) && u.userContactNumber == contactNum && u.userType == 11))
     {
         user    usr      = (from c in db.users where (c.userName == userNameOrEmail || c.userEmail == userNameOrEmail) && c.userContactNumber == contactNum select c).FirstOrDefault();
         DTOuser toReturn = new DTOuser(usr);
         return(toReturn);
     }
     //returns null if user not registered/incorrect details
     return(null);
 }
        public async Task <IHttpActionResult> consumerDeactivateProfile(int userID)
        {
            //user Table:
            user    toUpdateUser = (from u in db.users where u.User_ID == userID select u).SingleOrDefault();
            DTOuser dtoUser      = new DTOuser(toUpdateUser);

            dtoUser.userIsActive = false;

            toUpdateUser = EntityMapper.updateEntity(toUpdateUser, dtoUser);
            db.Entry(toUpdateUser).State = EntityState.Modified;
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.OK));
        }
        public async Task <IHttpActionResult> deleteUser(int id)
        {
            var userToDel = db.users.SingleOrDefault(x => x.User_ID == id);

            if (userToDel == null)
            {
                return(NotFound());
            }

            DTOuser temp = new DTOuser(userToDel);

            db.users.Remove(userToDel);
            await db.SaveChangesAsync();

            return(Ok(temp));
        }
Exemple #15
0
        //post user - return true if user created. userType - 11 for consumer & 21 for reseller
        public async Task <IHttpActionResult> postReseller(string fName, string lName, string userName, string email, string contactNum, string userPass, string IDnumber, string cardNumber, string cardExpiration, string cardCVV, string nameOnCard, string bankName, DateTime DOB)
        {
            DTOuser newUser = await postUser(fName, lName, userName, email, contactNum, userPass, 21, IDnumber);

            if (newUser.userFirstName == null && newUser.userLastName == null)
            {
                if (newUser.userName == "-1")
                {
                    return(BadRequest("Username taken"));
                }
                else if (newUser.userEmail == "-1")
                {
                    return(BadRequest("email taken"));
                }
                else
                {
                    return(BadRequest("Invalid user"));
                }
            }

            reseller tmp = new reseller();

            tmp.Reseller_ID              = newUser.User_ID;
            tmp.User_ID                  = newUser.User_ID;
            tmp.resellerIsValidated      = true;
            tmp.cardNumber               = cardNumber;
            tmp.cardExpirationMonth_Year = cardExpiration;
            tmp.cardCVV                  = cardCVV;
            tmp.nameOnCard               = nameOnCard;
            tmp.resellerBankName         = bankName;
            tmp.resellerDateOfBirth      = DOB;
            tmp.isSharingLocation        = "false";

            tmp.resellerBankBranchName    = "";
            tmp.resellerBankAccountNumber = "";
            tmp.resellerBankBranchCode    = "";

            db.resellers.Add(tmp);
            db.SaveChanges();

            return(Ok());
        }
        public IHttpActionResult getSentBulkVoucherUserDetails(int resellerUserID)
        {
            if (isUserReseller(resellerUserID))
            {
                List <vouchertransaction> rawVoucherTransactionList = (from c in db.vouchertransactions where c.Sender_ID == resellerUserID && c.TransactionType_ID == 2 orderby c.VoucherSentTo select c).ToList();


                if (rawVoucherTransactionList == null)
                {
                    return(NotFound());
                }
                else
                {
                    List <DTOvouchertransaction> voucherTransactionList = new List <DTOvouchertransaction>();
                    int     voucherSentToID     = rawVoucherTransactionList.First().VoucherSentTo;
                    decimal tmpTransactionValue = 0;
                    int     index = 0;
                    foreach (vouchertransaction vt in rawVoucherTransactionList)
                    {
                        if (index + 1 == rawVoucherTransactionList.Count)
                        {
                            tmpTransactionValue += Math.Abs(vt.transactionAmount);
                            DTOvouchertransaction tmpVoucherTransaction = new DTOvouchertransaction();
                            tmpVoucherTransaction.Sender_ID          = rawVoucherTransactionList.ElementAt(index - 1).Sender_ID;
                            tmpVoucherTransaction.Receiver_ID        = rawVoucherTransactionList.ElementAt(index - 1).Receiver_ID;
                            tmpVoucherTransaction.TransactionType_ID = 2;
                            tmpVoucherTransaction.transactionAmount  = tmpTransactionValue;
                            tmpVoucherTransaction.transactionDate    = rawVoucherTransactionList.ElementAt(index - 1).transactionDate;
                            tmpVoucherTransaction.VoucherSentTo      = rawVoucherTransactionList.ElementAt(index - 1).VoucherSentTo;
                            voucherTransactionList.Add(tmpVoucherTransaction);
                        }
                        else if (voucherSentToID == vt.VoucherSentTo)
                        {
                            tmpTransactionValue += Math.Abs(vt.transactionAmount);
                        }
                        else
                        {
                            DTOvouchertransaction tmpVoucherTransaction = new DTOvouchertransaction();
                            tmpVoucherTransaction.Sender_ID          = rawVoucherTransactionList.ElementAt(index - 1).Sender_ID;
                            tmpVoucherTransaction.Receiver_ID        = rawVoucherTransactionList.ElementAt(index - 1).Receiver_ID;
                            tmpVoucherTransaction.TransactionType_ID = 2;
                            tmpVoucherTransaction.transactionAmount  = tmpTransactionValue;
                            tmpVoucherTransaction.transactionDate    = rawVoucherTransactionList.ElementAt(index - 1).transactionDate;
                            tmpVoucherTransaction.VoucherSentTo      = rawVoucherTransactionList.ElementAt(index - 1).VoucherSentTo;
                            voucherTransactionList.Add(tmpVoucherTransaction);
                            voucherSentToID     = vt.VoucherSentTo;
                            tmpTransactionValue = Math.Abs(vt.transactionAmount);
                        }
                        index++;
                    }

                    List <DTOresellerSentVoucher_withUserDetails> list = new List <DTOresellerSentVoucher_withUserDetails>();
                    foreach (DTOvouchertransaction v in voucherTransactionList)
                    {
                        DTOuser tmp = new DTOuser(db.users.Single(x => v.Receiver_ID == x.User_ID));
                        list.Add(new DTOresellerSentVoucher_withUserDetails(v, tmp));
                    }
                    return(Ok(list));
                }
            }
            else
            {
                return(BadRequest("User is not a valid reseller"));
            }
        }
 public DTOresellerSentVoucher_withUserDetails(DTOvouchertransaction voucherTransaction, DTOuser user)
 {
     amount        = voucherTransaction.transactionAmount;
     dateSent      = voucherTransaction.transactionDate;
     userFirstName = user.userFirstName;
     userName      = user.userName;
 }