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)); }
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 async Task <IHttpActionResult> put(int id, DTOconsumer dtoconsumer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dtoconsumer.Consumer_ID) { return(BadRequest()); } var putUser = db.consumers.Single(e => e.Consumer_ID == id); db.Entry(EntityMapper.updateEntity(putUser, dtoconsumer)).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!userExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static consumer updateEntity(consumer entityObjct, DTOconsumer dto) { if (entityObjct == null) { entityObjct = new consumer(); } entityObjct.Consumer_ID = dto.Consumer_ID; entityObjct.User_ID = dto.User_ID; entityObjct.consumerDateOfBirth = dto.consumerDateOfBirth; entityObjct.consumerAddress = dto.consumerAddress; entityObjct.gender = dto.gender; entityObjct.maritalStatus = dto.maritalStatus; entityObjct.topProductCategoriesInterestedIn = dto.topProductCategoriesInterestedIn; entityObjct.homeOwnerType = dto.homeOwnerType; entityObjct.employmentStatus = dto.employmentStatus; entityObjct.grossMonthlyIncome = dto.grossMonthlyIncome; entityObjct.nettMonthlyIncome = dto.nettMonthlyIncome; entityObjct.totalMonthlyExpenses = dto.totalMonthlyExpenses; entityObjct.Location_ID = dto.Location_ID; entityObjct.numDependant = dto.numDependant; entityObjct.numClaims = dto.numClaims; entityObjct.ageGroup_ID = dto.ageGroup_ID; return(entityObjct); }
public async Task <DTOconsumer> Postconsumer(DTOconsumer newDTO) { consumer newProd = EntityMapper.updateEntity(null, newDTO); db.consumers.Add(newProd); await db.SaveChangesAsync(); return(newDTO); }
public async Task <IHttpActionResult> Putconsumer(int ID, DTOconsumer editedDTO) { consumer toUpdate = db.consumers.Find(ID); toUpdate = EntityMapper.updateEntity(toUpdate, editedDTO); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> getConsumer(int id) { DTOconsumer toReturn = new DTOconsumer(await db.consumers.FindAsync(id)); if (toReturn == null) { return(NotFound()); } return(CreatedAtRoute("DefaultApi", new { id = toReturn.Consumer_ID }, toReturn)); }
public async Task <IHttpActionResult> incrementConsumerNumClaims(int consumerID) { consumer toUpdate = (from c in db.consumers where c.Consumer_ID == consumerID select c).SingleOrDefault(); DTOconsumer dtoCons = new DTOconsumer(toUpdate); dtoCons.numClaims = dtoCons.numClaims + 1; toUpdate = EntityMapper.updateEntity(toUpdate, dtoCons); db.Entry(toUpdate).State = EntityState.Modified; await db.SaveChangesAsync(); return(StatusCode(HttpStatusCode.NoContent)); }
//POST a consumer public async Task <IHttpActionResult> postConsumer(DTOconsumer dtoConsumer) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.consumers.Add(EntityMapper.updateEntity(null, dtoConsumer)); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = dtoConsumer.Consumer_ID }, dtoConsumer)); }
public async Task <IHttpActionResult> putAdditionalSignUpInfo(int userID, string consumerAddress, string homeOwnerType, Nullable <int> numDependants, string topProductsInterestedIn, Nullable <decimal> grossMonthly, Nullable <decimal> nettMonthly, Nullable <decimal> totalExpenses) { consumer toUpdate = (from c in db.consumers where c.User_ID == userID select c).SingleOrDefault(); DTOconsumer dtoConsumer = new DTOconsumer(toUpdate); dtoConsumer.consumerAddress = consumerAddress; 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)); }