public ActionResult addUnitRate(FormCollection collection) { int check = (int)Session["add_unitRate"]; string good = collection["good"]; if (check == 0) { return(RedirectToAction("Index", "Home")); } string name = collection["account"]; TransactionAccount transAccount = service.findJvTransaction(name); service.findAndSetUnitRates(transAccount.id, good); UnitRate uRate = new UnitRate(); uRate.account_id = transAccount.id; uRate.good = collection["good"]; uRate.rate = float.Parse(collection["rate"]); uRate.is_active = "Y"; uRate.updated_at = DateTime.UtcNow; uRate.created_at = uRate.updated_at; service.addUnitRate(uRate); service.save(); return(RedirectToAction("unitRate")); }
public double findRate(int id, string name) { try { UnitRate unit = db.UnitRates.Where(x => x.account_id == id & x.good == name & x.is_active == "Y").First(); return(unit.rate); } catch (Exception e) { return(0); } }
public async Task <ApiResponse> Handle(GetUnitRateByActivityTypeIdQuery request, CancellationToken cancellationToken) { ApiResponse response = new ApiResponse(); try { var activity = await _dbContext.ActivityTypes.AsNoTracking().AsQueryable().FirstOrDefaultAsync(x => x.IsDeleted == false && x.ActivityTypeId == request.ActivityTypeId); UnitRate unitRateById = new UnitRate(); if (activity.ActivityName == "Broadcasting") { unitRateById = await _dbContext.UnitRates.AsNoTracking().AsQueryable().FirstOrDefaultAsync(x => x.ActivityTypeId == request.ActivityTypeId && x.TimeCategoryId == request.TimeCategoryId && x.MediumId == request.MediumId && x.CurrencyId == request.CurrencyId && x.IsDeleted == false); } if (activity.ActivityName == "Production") { unitRateById = await _dbContext.UnitRates.AsNoTracking().AsQueryable().FirstOrDefaultAsync(x => x.ActivityTypeId == request.ActivityTypeId && x.MediumId == request.MediumId && x.NatureId == request.NatureId && x.QualityId == request.QualityId && x.CurrencyId == request.CurrencyId && x.IsDeleted == false); } if (unitRateById == null) { response.StatusCode = StaticResource.notFoundCode; response.data.UnitRateByActivityId = unitRateById; response.Message = StaticResource.unitRateNotFound; } else { response.StatusCode = StaticResource.successStatusCode; response.data.UnitRateByActivityId = unitRateById; } } catch (Exception ex) { response.StatusCode = StaticResource.failStatusCode; response.Message = ex.Message; } return(response); }
public void addUnitRate(UnitRate good) { db.UnitRates.Add(good); return; }
public async Task <ApiResponse> Handle(AddEditUnitRateCommand request, CancellationToken cancellationToken) { ApiResponse response = new ApiResponse(); UnitRate unitRateDetails = new UnitRate(); ActivityType activityDetail = await _dbContext.ActivityTypes.FirstOrDefaultAsync(x => x.ActivityTypeId == request.ActivityTypeId); string activity = activityDetail.ActivityName; if (activity == "Broadcasting") { unitRateDetails = await _dbContext.UnitRates.FirstOrDefaultAsync(x => x.ActivityTypeId == request.ActivityTypeId && x.CurrencyId == request.CurrencyId && x.MediumId == request.MediumId && x.TimeCategoryId == request.TimeCategoryId && x.MediaCategoryId == request.MediaCategoryId && x.QualityId == request.QualityId && x.IsDeleted == false); } if (activity == "Production") { unitRateDetails = await _dbContext.UnitRates.FirstOrDefaultAsync(x => x.ActivityTypeId == request.ActivityTypeId && x.CurrencyId == request.CurrencyId && x.QualityId == request.QualityId && x.MediumId == request.MediumId && x.NatureId == request.NatureId && x.MediaCategoryId == request.MediaCategoryId && x.IsDeleted == false); } try { if (request.UnitRateId == 0 || request.UnitRateId == null) { if (unitRateDetails == null) { UnitRate obj = new UnitRate(); obj.CreatedById = request.CreatedById; obj.CreatedDate = request.CreatedDate; obj.IsDeleted = false; obj.ActivityTypeId = request.ActivityTypeId; obj.CurrencyId = request.CurrencyId; obj.UnitRates = request.UnitRates; obj.MediumId = request.MediumId; obj.NatureId = request.NatureId; obj.QualityId = request.QualityId; obj.TimeCategoryId = request.TimeCategoryId; obj.MediaCategoryId = request.MediaCategoryId; _mapper.Map(request, obj); await _dbContext.UnitRates.AddAsync(obj); await _dbContext.SaveChangesAsync(); request.ActivityName = activity; request.UnitRateId = obj.UnitRateId; response.data.unitRateDetails = request; response.StatusCode = StaticResource.successStatusCode; response.Message = "Unit Rate Added Successfully"; } else { var obj = await _dbContext.UnitRates.FirstOrDefaultAsync(x => x.UnitRateId == request.UnitRateId && x.IsDeleted == false); if (obj == null) { response.Message = StaticResource.unitRateExists; } } } else { var obj1 = await _dbContext.UnitRates.FirstOrDefaultAsync(x => x.UnitRateId == request.UnitRateId && x.IsDeleted == false); if (unitRateDetails != null) { if (obj1 != null) { if (obj1.UnitRates == request.UnitRates) { response.Message = StaticResource.unitRateExists; } else { obj1.UnitRates = request.UnitRates; await _dbContext.SaveChangesAsync(); response.data.unitRateDetailsById = obj1; response.StatusCode = StaticResource.successStatusCode; response.Message = "Unit Rate updated Successfully"; } } } else { obj1.ModifiedById = request.ModifiedById; obj1.ModifiedDate = request.ModifiedDate; obj1.ActivityTypeId = request.ActivityTypeId; obj1.CurrencyId = request.CurrencyId; obj1.MediumId = request.MediumId; obj1.NatureId = request.NatureId; obj1.QualityId = request.QualityId; obj1.TimeCategoryId = request.TimeCategoryId; obj1.MediaCategoryId = request.MediaCategoryId; obj1.UnitRates = request.UnitRates; await _dbContext.SaveChangesAsync(); response.data.unitRateDetailsById = obj1; response.StatusCode = StaticResource.successStatusCode; response.Message = "Unit Rate updated Successfully"; } var activityDetails = await _dbContext.ActivityTypes.FirstOrDefaultAsync(x => x.ActivityTypeId == request.ActivityTypeId); request.ActivityName = activityDetails.ActivityName; } } catch (Exception ex) { response.StatusCode = StaticResource.failStatusCode; response.Message = ex.Message; } return(response); }