public static ResultObject GetMostProfitableList(int?month) { try { if (month == null) { throw new BusinessException(Errors.Codes.DateEmpty); } ABCEntities context = new ABCEntities(); List <MODEL_DETAILS> modelsDetails = context.MODEL_DETAILS.AsNoTracking().ToList(); List <ModelWithCostAndProfit> modelsWithCostAndProfit = GeneralWrapper.CalculateCostsAndProfits(month.Value, modelsDetails); ModelWithCostAndProfit modelWithMostProfit = modelsWithCostAndProfit.OrderByDescending(m => m.Profit).FirstOrDefault(); List <ModelWithCostAndProfit> result = new List <ModelWithCostAndProfit>(); if (modelWithMostProfit != null) { result = modelsWithCostAndProfit.Where(m => m.Profit == modelWithMostProfit.Profit).ToList(); } return(BasicWrapper.SuccessResult(result)); } catch (BusinessException exp) { return(BasicWrapper.ErrorResult(exp.Code, exp.Message)); } catch (Exception exp) { return(BasicWrapper.GeneralErrorResult()); } }
public static ResultObject GetColors() { try { ABCEntities context = new ABCEntities(); List <COLOR> colors = context.COLOR.AsNoTracking().ToList(); return(BasicWrapper.SuccessResult(GeneralWrapper.Colors(colors))); } catch (BusinessException exp) { return(BasicWrapper.ErrorResult(exp.Code, exp.Message)); } catch (Exception exp) { return(BasicWrapper.GeneralErrorResult()); } }
public static ResultObject GetTypes() { try { ABCEntities context = new ABCEntities(); List <TYPE> types = context.TYPE.AsNoTracking().ToList(); return(BasicWrapper.SuccessResult(GeneralWrapper.Types(types))); } catch (BusinessException exp) { return(BasicWrapper.ErrorResult(exp.Code, exp.Message)); } catch (Exception exp) { return(BasicWrapper.GeneralErrorResult()); } }
public static ResultObject GetProfitableList(int?month) { try { if (month == null) { throw new BusinessException(Errors.Codes.DateEmpty); } ABCEntities context = new ABCEntities(); List <MODEL_DETAILS> modelsDetails = context.MODEL_DETAILS.AsNoTracking().ToList(); List <ModelWithCostAndProfit> modelsWithCostAndProfit = GeneralWrapper.CalculateCostsAndProfits(month.Value, modelsDetails); List <Model> result = new List <Model>(); foreach (var model in modelsWithCostAndProfit) { if (model.Profit <= 0) { continue; } result.Add(new Model() { ColorId = model.ColorId, ColorName = model.ColorName, Id = model.Id, IsConvertible = model.IsConvertible, Price = model.Price, TypeId = model.TypeId, TypeName = model.TypeName }); } return(BasicWrapper.SuccessResult(result)); } catch (BusinessException exp) { return(BasicWrapper.ErrorResult(exp.Code, exp.Message)); } catch (Exception exp) { return(BasicWrapper.GeneralErrorResult()); } }
public static ResultObject Add(Model model) { try { if (model == null) { throw new BusinessException(Errors.Codes.ModelNotExist); } ABCEntities context = new ABCEntities(); Colors.checkColor(model.ColorId, context); Types.checkType(model.TypeId, context); if (model.IsConvertible == null) { model.IsConvertible = 0; } if (model.IsConvertible > 1) { model.IsConvertible = 1; } checkUniqueModel(model.ColorId.Value, model.TypeId.Value, model.IsConvertible.Value, context); context.MODEL.Add(new MODEL() { COLOR_ID = model.ColorId.Value, CONVERTIBLE = model.IsConvertible.Value, TYPE_ID = model.TypeId.Value }); context.SaveChanges(); return(BasicWrapper.SuccessResult(new object())); } catch (BusinessException exp) { return(BasicWrapper.ErrorResult(exp.Code, exp.Message)); } catch (Exception exp) { return(BasicWrapper.GeneralErrorResult()); } }