Skip to content

Commit

Permalink
implemented address update method and implemented shipping price with…
Browse files Browse the repository at this point in the history
… chckout total price
  • Loading branch information
NisanurBulut committed Dec 5, 2020
1 parent e02d3fd commit d36c1b9
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Camekan.API/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@ public class AccountController : BaseApiController
private readonly UserManager<AppUser> _userManager;
private readonly SignInManager<AppUser> _signInManager;
private readonly ITokenService _tokenService;
private readonly IAddressRepository _addressRepository;
private readonly IMapper _mapper;
public AccountController(UserManager<AppUser> userManager,
SignInManager<AppUser> signInManager,
IAddressRepository addressRepository,
ITokenService tokenService, IMapper mapper)
{
_userManager = userManager;
_signInManager = signInManager;
_tokenService = tokenService;
_addressRepository = addressRepository;
_mapper = mapper;
}

Expand All @@ -36,6 +33,7 @@ public AccountController(UserManager<AppUser> userManager,
public async Task<ActionResult<AppUserDto>> GetCurrentUser()
{
var user = await _userManager.FindByEmailFromClaimsPrincipalAsync(HttpContext.User);
if (user == null) return Ok(new AppUserDto());
return Ok(new AppUserDto
{
Email = user.Email,
Expand Down
4 changes: 2 additions & 2 deletions Camekan.API/Extensions/UserManagerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public static async Task<AppUser> FindUserByClaimsPrincipleWithAddressAsync(this
{
var email = user.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.Email)?.Value;
// join dene

return await input.Users.Include(a=>a.Id).Include(a=>a.Address).SingleOrDefaultAsync(a => a.Email == email);
var appUser= await input.Users.Include(a => a.Address).FirstOrDefaultAsync(a => a.Email == email);
return appUser;
}
public static async Task<AppUser> FindByEmailFromClaimsPrincipalAsync(this UserManager<AppUser> input, ClaimsPrincipal user)
{
Expand Down
9 changes: 7 additions & 2 deletions Camekan.Client/src/app/basket/basket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { environment } from 'src/environments/environment';
import { Basket, IBasket } from '../shared/models/basket.model';
import { IBasketItem } from '../shared/models/basketItem.model';
import { IBasketTotal } from '../shared/models/basketTotal.model';
import { IDeliveryMethod } from '../shared/models/deliveryMethod.model';
import { IProduct } from '../shared/models/product.model';

@Injectable({
Expand All @@ -18,9 +19,13 @@ export class BasketService {
private basketTotalSource = new BehaviorSubject<IBasketTotal>(null);
basketTotal$ = this.basketTotalSource.asObservable();
basket$ = this.basketSource.asObservable();

shippingPrice = 0;
constructor(private http: HttpClient) { }

setShippingPrice(deliveryMethod: IDeliveryMethod): void {
this.shippingPrice = deliveryMethod.price;
this.calculateTotal();
}
getBasket(id: string) {
return this.http.get(this.baseUrl + '/basket?id=' + id)
.pipe(
Expand Down Expand Up @@ -96,7 +101,7 @@ export class BasketService {

private calculateTotal() {
const basket = this.getCurrenctBasketValue();
const shipping = 0;
const shipping = this.shippingPrice;
const subTotal = basket.items.reduce((a, b) => (b.price * b.quantity) + a, 0);
const total = subTotal;
this.basketTotalSource.next({ shipping, total, subTotal });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<div class="d-flex justify-content-between align-content-center">
<h4>Teslimat Adresi</h4>
<button (click)="saveUserAddress()"
[disabled]="!checkoutForm.get('addressForm').valid || !checkoutForm.get('addressForm').dirty" class="btn btn-outline-success mb-3">Kaydet</button>
[disabled]="!checkoutForm.get('addressForm').valid || !checkoutForm.get('addressForm').dirty"
class="btn btn-outline-success mb-3">Kaydet</button>
</div>
<div class="row" formGroupName="addressForm">
<div class="form-group col-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class CheckoutAddressComponent implements OnInit {
saveUserAddress() {
this.accountService.updateUserAddress(this.checkoutForm.get('addressForm').value)
.subscribe(() => {
this.toastrService.success('adres kaydedildi.');
this.toastrService.success('Adres kaydedildi.');
}, error => this.toastrService.error(error.message));
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<div class="mt-4" [formGroup]="checkoutForm">
<div class="row" formGroupName="deliveryForm">
<div class="row ml-5" formGroupName="deliveryForm">
<div class="form-group col-6" *ngFor="let item of deliveryMethods">
<input
type="radio"
id="{{ item.id }}"
value="{{ item.id }}"
(click)="setShippingPrice(item)"
formControlName="deliveryMethod"
class="custom-control-class"
class="custom-control-class mr-3"
/>
<label for="{{ item.id }}" class="custom-control-class">
<strong>{{ item.shortName }} - {{ item.price | currency }}</strong>
<strong>{{ item.shortName }} - {{ item.price | currency: "TRY":"₺":"" }}</strong>
</label>
<br />
<span class="label-description">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { BasketService } from 'src/app/basket/basket.service';
import { IDeliveryMethod } from 'src/app/shared/models/deliveryMethod.model';
import { CheckoutService } from '../checkout.service';

Expand All @@ -11,11 +12,14 @@ import { CheckoutService } from '../checkout.service';
export class CheckoutDeliveryComponent implements OnInit {
@Input() checkoutForm: FormGroup;
deliveryMethods: IDeliveryMethod[];
constructor(private checkOutService: CheckoutService) { }
constructor(private checkOutService: CheckoutService, private basketService: BasketService) { }

ngOnInit(): void {
this.getDeliveryMethods();
}
setShippingPrice(deliveryMethod: IDeliveryMethod) {
this.basketService.setShippingPrice(deliveryMethod);
}
getDeliveryMethods() {
this.checkOutService.getDeliveryMethods()
.subscribe((dm: IDeliveryMethod[]) => {
Expand Down
Binary file modified Camekan.DataAccess/Camekan.db-shm
Binary file not shown.
Binary file modified Camekan.DataAccess/Camekan.db-wal
Binary file not shown.
6 changes: 3 additions & 3 deletions Camekan.DataAccess/Context/DatabaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.ApplyConfiguration(new OrderConfiguration());
modelBuilder.ApplyConfiguration(new OrderItemConfiguration());
modelBuilder.ApplyConfiguration(new ProductConfiguration());
//modelBuilder.ApplyConfiguration(new AppUserConfiguration());
//modelBuilder.ApplyConfiguration(new AddressConfiguration());
modelBuilder.ApplyConfiguration(new AppUserConfiguration());
modelBuilder.ApplyConfiguration(new AddressConfiguration());



modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}
public DbSet<AddressEntity> tAddress { get; set; }
Expand Down

0 comments on commit d36c1b9

Please sign in to comment.