Esempio n. 1
0
        public async Task UploadLog(RepairLog log)
        {
            FirestoreDb db =
                connection.GetFirestoreDb();

            CollectionReference colRef = db
                                         .Collection("activity-log");

            DocumentReference docRef = null;

            Dictionary <string, object> repairIdDoc =
                new Dictionary <string, object>()
            {
                { "RepairId", log.RepairId }
            };

            await db.RunTransactionAsync(async t => {
                docRef = await colRef.AddAsync(repairIdDoc);
            });

            CollectionReference subDocRef =
                docRef.Collection("logs");

            await db.RunTransactionAsync(async t => {
                await subDocRef.AddAsync(log);
            });
        }
Esempio n. 2
0
        public async void UploadRepair(
            string serviceName,
            AddRepairBindingModel repair)
        {
            FirestoreDb db = connection.GetFirestoreDb();

            CollectionReference repairsColRef = db
                                                .Collection("service-repairs");

            Repair repairModel = new Repair(repair);

            if (repairModel.BoughtAt.Day == 29 &&
                repairModel.BoughtAt.Month == 2)
            {
                int warrantyInYears = repairModel.WarrantyPeriod / 12;

                if (warrantyInYears % 4 == 0)
                {
                    repairModel.WarrantyExpiresOn =
                        repairModel.BoughtAt.AddYears(warrantyInYears);
                }
                else
                {
                    repairModel.WarrantyExpiresOn =
                        repairModel.BoughtAt.AddYears(warrantyInYears)
                        .AddDays(1);
                }
            }
            else
            {
                int warrantyInYears = repairModel.WarrantyPeriod / 12;

                repairModel.WarrantyExpiresOn =
                    repairModel.BoughtAt.AddYears(warrantyInYears);
            }

            await db
            .RunTransactionAsync(async transaction => {
                UpdateRepairId(serviceName,
                               repairModel.RepairId);

                await repairsColRef.AddAsync(repairModel);
            });

            RepairLog log = new RepairLog()
            {
                TimeOfEvent = DateTime.UtcNow,
                RepairId    = repairModel.RepairId,
                TypeOfEvent = "create",
                Status      = repairModel.RepairStatus,
                Description = $"Add repair with id {repairModel.RepairId}"
            };

            UploadLog(log);
        }
Esempio n. 3
0
        public void AddRepairLog(RepairLogView log)
        {
            using var ctx = new WorkshopContext();
            RepairLog newLog = new RepairLog();

            newLog.Date         = log.Date;
            newLog.Description  = log.Description;
            newLog.Repair       = ctx.Repairs.SingleOrDefault(r => r.Id == log.Repair.Id);
            newLog.TechnicianId = log.TechnicianId;
            ctx.RepairLogs.Add(newLog);
            ctx.SaveChanges();
        }
Esempio n. 4
0
        public async Task UploadLog(RepairLog log)
        {
            FirestoreDb db =
                connection.GetFirestoreDb();

            CollectionReference colRef = db
                                         .Collection("activity-log");

            await db.RunTransactionAsync(async t => {
                await colRef.AddAsync(log);
            });
        }
Esempio n. 5
0
        public void UpdateRepairLog(RepairLogView log)
        {
            using var ctx = new WorkshopContext();
            RepairLog updatedLog = ctx.RepairLogs.Single(rl => rl.Id == log.Id);

            updatedLog.Repair       = ctx.Repairs.SingleOrDefault(r => r.Id == log.Repair.Id);
            updatedLog.Id           = log.Id;
            updatedLog.Description  = log.Description;
            updatedLog.Date         = log.Date;
            updatedLog.TechnicianId = log.TechnicianId;
            ctx.RepairLogs.Update(updatedLog);
            ctx.SaveChanges();
        }
Esempio n. 6
0
        public static RepairLogView GetViewModell(RepairLog rl)
        {
            RepairLogView rlv = new RepairLogView();

            if (rl != null)
            {
                rlv.Id           = rl.Id;
                rlv.Date         = rl.Date;
                rlv.Description  = rl.Description;
                rlv.Repair       = GetViewModell(rl.Repair);
                rlv.TechnicianId = rl.TechnicianId;
            }
            return(rlv);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public async Task UploadLogToExistingRepair(int id, RepairLog log)
        {
            FirestoreDb         db     = connection.GetFirestoreDb();
            CollectionReference colRef = db
                                         .Collection("activity-log");

            QuerySnapshot snapshot = colRef
                                     .WhereEqualTo("RepairId", id)
                                     .Limit(1)
                                     .GetSnapshotAsync()
                                     .Result;

            CollectionReference subColRef = snapshot
                                            .Documents
                                            .FirstOrDefault()
                                            .Reference
                                            .Collection("logs");

            await db.RunTransactionAsync(async t => {
                await subColRef.AddAsync(log);
            });
        }
Esempio n. 9
0
 public async void AddLogToExistingRepair([FromBody] RepairLog log)
 {
     await service.UploadLogToExistingRepair(log.RepairId, log);
 }
Esempio n. 10
0
 public async void AddLog([FromBody] RepairLog log)
 {
     await service.UploadLog(log);
 }
Esempio n. 11
0
 public async void UploadLog(RepairLog log)
 {
     LogService service = new LogService();
     await service.UploadLog(log);
 }
Esempio n. 12
0
        public async void SendPartToRepair(int id, string partNumber, int qnt)
        {
            FirestoreDb db = connection.GetFirestoreDb();

            CollectionReference colRef = db
                                         .Collection("warehouse-parts");

            QuerySnapshot snapshot = colRef
                                     .WhereEqualTo("PartNumber", partNumber)
                                     .GetSnapshotAsync()
                                     .Result;

            if (snapshot.Count == 0)
            {
                return;
            }
            else
            {
                WarehousePart part = new List <DocumentSnapshot>
                                         (snapshot.Documents)
                                     .OrderByDescending(x => x.CreateTime)
                                     .FirstOrDefault()
                                     .ConvertTo <WarehousePart>();

                if (part.Availability < qnt)
                {
                    return;
                }
                else
                {
                    snapshot.Documents
                    .ToList()
                    .ForEach(async x => {
                        WarehousePart p = x.ConvertTo <WarehousePart>();
                        p.Availability -= qnt;

                        await x
                        .Reference
                        .UpdateAsync("Availability", p.Availability);
                    });

                    QuerySnapshot qs = db
                                       .Collection("repair-parts")
                                       .WhereEqualTo("RepairId", id)
                                       .Limit(1)
                                       .GetSnapshotAsync()
                                       .Result;

                    RequestPartBindingModel parts = qs
                                                    .Documents
                                                    .FirstOrDefault()
                                                    .ConvertTo <RequestPartBindingModel>();

                    parts.PartsForRepair[partNumber] = qnt;

                    await qs.Documents
                    .FirstOrDefault()
                    .Reference
                    .UpdateAsync("PartsForRepair", parts.PartsForRepair);

                    RepairLog log = new RepairLog()
                    {
                        TimeOfEvent = DateTime.UtcNow,
                        TypeOfEvent = "update part qnt",
                        Description = "Update part qnt"
                    };

                    await new LogService()
                    .UploadLogToExistingRepair(id, log);
                }
            }
        }
Esempio n. 13
0
        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);
            }
        }