public async Task <ActionResult <VesselCharge> > Post(VesselCharge vesselCharge) { string eMail = string.Empty; using (Utility util = new Utility()) { eMail = util.GetEmailclaim(User.Identity as ClaimsIdentity); } if (vesselCharge.Id > 0) { vesselCharge.UpdatedBy = eMail; await _repository.UpdateAsync <VesselCharge>(vesselCharge); } else { vesselCharge.CreatedBy = eMail; await _repository.AddAsync <VesselCharge>(vesselCharge); } return(await GetVesselCharge(vesselCharge.Id)); }
/// <summary> /// For Admin /// </summary> /// <param name="schedule"></param> /// <param name="currencyCode"></param> /// <returns></returns> public List <VesselCharge> BuildVesselChargeEntitites(VesselSchedule schedule, string currencyCode) { List <VesselCharge> finalList = new List <VesselCharge>(); int currencyId = 1; var currency = _repository.FindSingle <Currency>(x => x.CurrencyCode == currencyCode); currencyId = currency == null ? 1 : currency.Id; int chargedAtId = 1; var chargedAt = _repository.FindSingle <ChargedAt>(x => x.Name == "ORIGIN"); chargedAtId = chargedAt == null ? 1 : chargedAt.Id; var pckList = _repository.ListAllAsyncWhere <Package>(x => x.IsActive == true).Result; var partnerList = _repository.ListAllAsyncWhere <Partner>(x => x.IsActive == true && x.PartnerName != "ADMIN").Result; //Source and DEstination x Partner X Package foreach (Package pck in pckList) { foreach (Partner prtner in partnerList) { VesselCharge charge = new VesselCharge() { ChargedAtId = chargedAtId, ChargeAmount = 200, ChargeDetail = "STD", PackageId = pck.Id, CurrencyId = currencyId, StartDate = schedule.EstDepDate, EndDate = schedule.EstArrDestDate, CreatedBy = "senthil", CreatedAt = new DateTime(), DestinationPortId = schedule.DestinationPortId, OriginPortId = schedule.OriginPortId, PartnerId = prtner.Id, IsActive = false, VesselScheduleId = schedule.Id, ChargeType = "chargeType", UpdatedAt = new DateTime(), UpdatedBy = "senthil", VesselSchedule = schedule, Package = pck, Partner = prtner, Currency = currency, DestinationPort = schedule.DestinationPort, OriginPort = schedule.OriginPort, ChargedAt = chargedAt, }; finalList.Add(charge); } } if (schedule.Details != null) { //source -origin and trasits as Destination X partner x Package var isDeleiveryAvailableList = schedule.Details.FindAll(x => x.IsDeliveryAvailable == true).ToList <ScheduleDetail>(); foreach (ScheduleDetail detail in isDeleiveryAvailableList) { foreach (Package pck in pckList) { foreach (Partner prtner in partnerList) { VesselCharge charge = new VesselCharge() { ChargedAtId = chargedAtId, ChargeAmount = 200, ChargeDetail = "STD", PackageId = pck.Id, CurrencyId = 1, StartDate = schedule.EstDepDate, EndDate = detail.ExpArrival, CreatedBy = "senthil", CreatedAt = new DateTime(), DestinationPortId = detail.TransitPortId, OriginPortId = schedule.OriginPortId, PartnerId = prtner.Id, IsActive = false, VesselScheduleId = schedule.Id, ChargeType = "chargeType", UpdatedAt = new DateTime(), UpdatedBy = "senthil", VesselSchedule = schedule, Package = pck, Partner = prtner, Currency = currency, DestinationPort = detail.TransitPort, OriginPort = schedule.OriginPort, ChargedAt = chargedAt }; finalList.Add(charge); } } } //source from transit and Destination x partner x package var isLoadingAvailable = schedule.Details.FindAll(x => x.IsLoadingAvailable == true).ToList <ScheduleDetail>(); foreach (ScheduleDetail detail in isLoadingAvailable) { foreach (Package pck in pckList) { foreach (Partner prtner in partnerList) { VesselCharge charge = new VesselCharge() { ChargedAtId = chargedAtId, ChargeAmount = 200, ChargeDetail = "STD", PackageId = pck.Id, CurrencyId = 1, CreatedBy = "senthil", StartDate = detail.ExpDeparture, EndDate = schedule.EstArrDestDate, CreatedAt = new DateTime(), DestinationPortId = schedule.DestinationPortId, OriginPortId = detail.TransitPortId, PartnerId = prtner.Id, IsActive = false, VesselScheduleId = schedule.Id, ChargeType = "chargeType", UpdatedAt = new DateTime(), UpdatedBy = "senthil", VesselSchedule = schedule, Package = pck, Partner = prtner, Currency = currency, DestinationPort = schedule.DestinationPort, OriginPort = detail.TransitPort, ChargedAt = chargedAt, }; finalList.Add(charge); } } } //transit 1 as source and transit 2...n as Destinaition x partner x package foreach (ScheduleDetail source in isLoadingAvailable)//this becomes source { foreach (ScheduleDetail destination in isDeleiveryAvailableList) { if (source.Id != destination.Id && source.ExpArrival < destination.ExpArrival) { foreach (Package pck in pckList) { foreach (Partner prtner in partnerList) { VesselCharge charge = new VesselCharge() { ChargedAtId = chargedAtId, ChargeAmount = 200, ChargeDetail = "STD", PackageId = pck.Id, CurrencyId = 1, StartDate = source.ExpDeparture, EndDate = destination.ExpArrival, CreatedBy = "senthil", CreatedAt = new DateTime(), DestinationPortId = destination.TransitPortId, OriginPortId = source.TransitPortId, PartnerId = prtner.Id, IsActive = false, VesselScheduleId = schedule.Id, ChargeType = "chargeType", UpdatedAt = new DateTime(), UpdatedBy = "senthil", VesselSchedule = schedule, Package = pck, Partner = prtner, Currency = currency, DestinationPort = destination.TransitPort, // _repository.FindSingle<Port>(x => x.Id == destination.TransitPortId), OriginPort = source.TransitPort, // _repository.FindSingle<Port>(x => x.Id == source.TransitPortId), ChargedAt = chargedAt, }; finalList.Add(charge); } } } } } } return(finalList); }