public IActionResult AddRate([FromBody] RateRequest request) { if (!ModelState.IsValid) { return(Ok(ModelState)); } var response = new BaseResponse <bool>(); if (rateRepo.Any(x => x.RecipeID == request.RecipeID && x.UserID == CurrentUserID)) { response.SetMessage("Daha önce oylama yapmışsınız"); return(Ok(response)); } var item = new RecipeRate { RecipeID = request.RecipeID, Rate = request.Rate, Status = Status.NotAppproved }; if (User.Identity.IsAuthenticated) { item.UserID = CurrentUserID; } rateRepo.Add(item); response.Message = "Değerlendirme başarıyla eklendi"; decimal avarageRate = 0; List <RecipeRate> ratedRecipe = new List <RecipeRate>(); ratedRecipe = rateRepo.GetBy(x => x.RecipeID == request.RecipeID).ToList(); foreach (var aa in ratedRecipe) { avarageRate += aa.Rate; } avarageRate = avarageRate / ratedRecipe.Count(); var ChangeAvarageRate = recipeRepo.FirstOrDefaultBy(x => x.Id == request.RecipeID); ChangeAvarageRate.AvarageRate = avarageRate; recipeRepo.Update(ChangeAvarageRate); return(Ok(response)); }
public static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Need the input file."); Console.Read(); return; } var inFile = args[0]; var outFile = inFile + ".json"; var outFile2 = inFile + ".txt"; if (!File.Exists(inFile)) { Console.WriteLine("File not found."); Console.Read(); return; } var isDone = false; try { // OBS: // It's better to convert using same class model // as the one used in AikaEmu.GameServer. var fileName = Path.GetFileNameWithoutExtension(inFile); if (fileName == null) { return; } BaseConvert convert = null; switch (fileName) { case "ItemList": convert = new ItemList(); break; case "npcpos": convert = new NpcPos(); break; case "MobPos": convert = new MobPos(); break; case "ExpList": convert = new ExpList(); break; case "PranExpList": convert = new PranExpList(); break; case "MN": convert = new Mn(); break; case "GearCore": convert = new GearCore(); break; case "ConvertCore": convert = new ConvertCore(); break; case "Title": convert = new Title(); break; case "Recipe": convert = new Recipe(); break; case "RecipeRate": convert = new RecipeRate(); break; case "ItemEffect": convert = new ItemEffect(); break; case "ReinforceA": case "ReinforceW": convert = new ReinforceA(); ((ReinforceA)convert).IsReinforceW = fileName == "ReinforceW"; break; case "Reinforce2": case "Reinforce3": convert = new Reinforce2(); break; case "MakeItems": convert = new MakeItems(); break; case "SetItem": convert = new SetItem(); break; case "SkillData": convert = new SkillData(); break; case "Quest": convert = new Quest(); break; case "Map": convert = new Map(); break; case "ObjPos": convert = new ObjPos(); break; case "SPosition": convert = new SPosition(); break; case "Dialog": convert = new Dialog(); break; case "StatusPoint": convert = new StatusPoint(); break; } if (convert != null) { convert.SetupFile(inFile, outFile, outFile2); convert.Convert(); convert.Save(); isDone = true; } } catch (Exception e) { Console.WriteLine(e); Console.Read(); throw; } finally { if (isDone) { Console.WriteLine("Input: " + Path.GetFileName(inFile)); Console.WriteLine("Output: " + Path.GetFileName(outFile)); Console.WriteLine("OutputSql: " + Path.GetFileName(outFile2)); Console.WriteLine("Converted with success."); } else { Console.WriteLine("Error in conversion."); } } Console.Read(); }