public Task <double> CalcRepairPrice(int id) { double total = 0; FirestoreDb db = connection.GetFirestoreDb(); QuerySnapshot snapshot = db .Collection("service-repairs") .WhereEqualTo("RepairId", id) .Limit(1) .GetSnapshotAsync() .Result; Repair repair = snapshot .FirstOrDefault() .ConvertTo <Repair>(); if (repair.RepairStatus.Contains("OOW") || repair.RepairStatus.Equals("Awaiting payment")) { total += repair.TechnicianLabor; QuerySnapshot qs = db .Collection("repair-parts") .WhereEqualTo("RepairId", id) .Limit(1) .GetSnapshotAsync() .Result; RequestPartBindingModel model = qs .FirstOrDefault() .ConvertTo <RequestPartBindingModel>(); foreach (KeyValuePair <string, int> x in model.PartsForRepair) { QuerySnapshot qst = db .Collection("warehouse-parts") .WhereEqualTo("PartNumber", x.Key) .Limit(1) .GetSnapshotAsync() .Result; WarehousePart part = qst .FirstOrDefault() .ConvertTo <WarehousePart>(); total += part.Price * x.Value; } qs .FirstOrDefault() .Reference .UpdateAsync("Total", total); } else { total = 0; } return(Task.FromResult(total)); }
GetLogsForRepair(int id) { FirestoreDb db = connection.GetFirestoreDb(); List <RepairLog> logs = new List <RepairLog>(); QuerySnapshot qs = db .Collection("activity-log") .WhereEqualTo("RepairId", id) .GetSnapshotAsync() .Result; string docId = qs .FirstOrDefault() .Reference .Id; Query getLogsQuery = db .Collection("activity-log") .Document(docId) .Collection("logs"); QuerySnapshot getLogs = getLogsQuery .GetSnapshotAsync().Result; Parallel.ForEach(getLogs.Documents, ds => { logs.Add(ds.ConvertTo <RepairLog>()); }); return(logs .OrderByDescending(x => x.TimeOfEvent) .ToList()); }
public async Task <Customer> GetAsync(string id) { QuerySnapshot querySnapshot = await _collection.GetSnapshotAsync(); DocumentSnapshot document = querySnapshot.FirstOrDefault(d => d.Id == id); if (document == null) { return(null); } return(document.ConvertTo <Customer>()); }
public async void UpdateRepair(RepairViewModel model) { FirestoreDb db = connection.GetFirestoreDb(); QuerySnapshot snapshot = db .Collection("service-repairs") .WhereEqualTo("RepairId", model.RepairId) .Limit(1) .GetSnapshotAsync() .Result; Repair repair = snapshot .FirstOrDefault() .ConvertTo <Repair>(); repair = NewRepair(model); repair.Notes = model.Notes; Dictionary <string, object> d = repair .GetType() .GetProperties() .ToDictionary(x => x.Name, x => x.GetValue(repair, null)); string logDesc = "Update repair card"; await snapshot.Documents .FirstOrDefault() .Reference .UpdateAsync(d); //modelAsDict // .ToList() // .ForEach(x => { // if(repairAsDict.ContainsKey(x.Key)) { // if(repairAsDict[x.Key] != x.Value) { // logDesc += $"\\n{x.Key} from {repairAsDict[x.Key]} to {x.Value}"; // } // } // }); RepairLog log = new RepairLog() { TimeOfEvent = DateTime.UtcNow, Description = logDesc, TypeOfEvent = "update" }; await new LogService() .UploadLogToExistingRepair(model.RepairId, log); }
public Task <StatusResult> GetRepairStatus(string name, string reclaim) { FirestoreDb db = connection.GetFirestoreDb(); StatusResult result = new StatusResult(); string repairNum = reclaim .Substring(reclaim.LastIndexOf("0") + 1); int id = int.Parse(repairNum); QuerySnapshot snapshot = db .Collection("service-repairs") .WhereEqualTo("CustomerName", name) .GetSnapshotAsync() .Result; result.Status = snapshot.FirstOrDefault() .ConvertTo <Repair>() .RepairStatus; QuerySnapshot qs = db.Collection("activity-log") .WhereEqualTo("RepairId", id) .GetSnapshotAsync() .Result; string docId = qs.FirstOrDefault().Id; QuerySnapshot getLog = db .Collection("activity-log") .Document(docId) .Collection("logs") .GetSnapshotAsync() .Result; result.Time = getLog .Where(x => x.ConvertTo <RepairLog>() .Description.Contains(result.Status)) .OrderByDescending(x => x.CreateTime) .FirstOrDefault() .ConvertTo <RepairLog>() .TimeOfEvent; return(Task.FromResult(result)); }
private async Task CreateAcceptPdf(int id, string notes) { ConnectionConfig connection = new ConnectionConfig(); FirestoreDb db = connection.GetFirestoreDb(); QuerySnapshot snapshot = await db .Collection("service-repairs") .WhereEqualTo("RepairId", id) .GetSnapshotAsync(); Repair repair = snapshot .FirstOrDefault() .ConvertTo <Repair>(); PdfDocument document = new PdfDocument(); document.Info.Title = "Created with PdfSharp"; PdfPage page = document.AddPage(); page.Size = PageSize.A4; XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Times New Roman", 36, XFontStyle.Bold); gfx.DrawString("Сервизна карта", font, XBrushes.Black, new XRect(0, 94, page.Width, page.Height), XStringFormats.TopCenter); string reclaim = "A"; for (int i = 0; i < 8 - repair.RepairId.ToString().Length; i++) { reclaim += "0"; } reclaim += repair.RepairId.ToString(); gfx.DrawString($"{reclaim} / {repair.CreatedAt.ToString("dd.MM.yyyy")}", new XFont("Times New Roman", 20, XFontStyle.Bold), XBrushes.Black, new XRect(0, 140, page.Width, page.Height), XStringFormats.TopCenter); gfx.DrawString("Издадена от: сервиз Бай Пешо", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(0, 170, page.Width, page.Height), XStringFormats.TopCenter); gfx.DrawString("Клиент:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(96, -190, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.CustomerName, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(96, -170, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Марка:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(347.5, -190, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.ApplianceBrand, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(347.5, -170, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Адрес:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(96, -150, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.CustomerAddress, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(96, -130, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Модел:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(347.5, -150, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.ApplianceModel, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(347.5, -130, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Телефон:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(96, -110, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.CustomerPhoneNumber, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(96, -90, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Сериен номер:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(347.5, -110, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.ApplianceSerialNumber, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(347.5, -90, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Дефект според клиента:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(96, -70, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.DefectByCustomer, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(96, -50, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("IMEI:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(347.5, -70, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.ApplianceProductCodeOrImei, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(347.5, -50, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Комплектация:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(96, -30, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.ApplianceEquipment, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(96, -10, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Дата на покупка:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(347.5, -30, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString($"{repair.BoughtAt.ToString("dd.MM.yyyy hh:MM:ss")}", new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(347.5, -10, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Доп. информация:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(96, 10, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.AdditionalInformation, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(96, 30, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Гаранционен период/месеци/:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(347.5, 10, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.WarrantyPeriod.ToString(), new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(347.5, 30, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Забележки външен вид:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(96, 50, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(notes, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(96, 70, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Покупка от:", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(347.5, 50, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString(repair.BoughtFrom, new XFont("Times New Roman", 14, XFontStyle.Regular), XBrushes.Black, new XRect(347.5, 70, page.Width, page.Height), XStringFormats.CenterLeft); gfx.DrawString("Приел в сервиза: ……………", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(0, 170, page.Width - 94, page.Height), XStringFormats.CenterRight); gfx.DrawString("/ Бай Пешо /", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(0, 190, page.Width - 94, page.Height), XStringFormats.CenterRight); gfx.DrawString("Предал: ………………………", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(0, 210, page.Width - 94, page.Height), XStringFormats.CenterRight); gfx.DrawString($"/ {repair.CustomerName} /", new XFont("Times New Roman", 14, XFontStyle.Bold), XBrushes.Black, new XRect(0, 230, page.Width - 94, page.Height), XStringFormats.CenterRight); string path = @$ "C:\Users\aleks\Desktop\Приемане-{repair.RepairId}.pdf";
public async void AddRequestedPartToRepair(string partNumber, int id) { FirestoreDb db = connection.GetFirestoreDb(); QuerySnapshot snapshot = db .Collection("repair-parts") .WhereEqualTo("RepairId", id) .GetSnapshotAsync() .Result; if (snapshot.Count == 0) { RequestPartBindingModel requestPart = new RequestPartBindingModel() { RepairId = id, PartsForRepair = new Dictionary <string, int>() { { partNumber, 1 } } }; CollectionReference colRef = db .Collection("repair-parts"); await db.RunTransactionAsync(async t => { await colRef.AddAsync(requestPart); }); RepairLog log = new RepairLog() { TimeOfEvent = DateTime.UtcNow, TypeOfEvent = "request part", Description = $"Request part with part number {partNumber}" }; await new LogService() .UploadLogToExistingRepair(id, log); } else { RequestPartBindingModel model = snapshot .FirstOrDefault() .ConvertTo <RequestPartBindingModel>(); if (model.PartsForRepair.ContainsKey(partNumber)) { ++model.PartsForRepair[partNumber]; } else { model.PartsForRepair.Add(partNumber, 1); } await snapshot .FirstOrDefault() .Reference .UpdateAsync("PartsForRepair", model.PartsForRepair); RepairLog log = new RepairLog() { TimeOfEvent = DateTime.UtcNow, TypeOfEvent = "update part qnt", Description = $"Update part qnt for {partNumber}" }; await new LogService() .UploadLogToExistingRepair(id, log); } }