Beispiel #1
0
        public bool AddUser(string adminPassword, User user)
        {
            try
            {
                using (var db = new DzoContext())
                {
                    if (db.Users.First(x => x.Login == "admin").Password == adminPassword)
                    {
                        if (!db.Users.Any(x => x.Login == user.Login))
                        {
                            db.Users.Add(user);
                            db.SaveChanges();
                            return(true);
                        }

                        Console.WriteLine("This user already exists!");
                    }
                    else
                    {
                        Console.WriteLine("Password is incorrect!");
                    }

                    return(false);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Something went wrong!");
                return(false);
            }
        }
Beispiel #2
0
 public bool DeleteActById(int id, Token token)
 {
     if (!Token.Exists(token))
     {
         return(false);
     }
     try
     {
         using (var db = new DzoContext())
         {
             var old = db.Acts.First(x => x.Id == id);
             db.Acts.Remove(old);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Beispiel #3
0
 public bool UpdateAct(ActBase act, Token token)
 {
     if (!Token.Exists(token))
     {
         return(false);
     }
     try
     {
         using (var db = new DzoContext())
         {
             var old = db.Acts.First(x => x.Id == act.Id);
             db.Acts.Remove(old);
             db.Acts.Add(act);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Beispiel #4
0
        public bool AddAct(ActBase act, Token token)
        {
            if (!Token.Exists(token))
            {
                return(false);
            }
            act.Region = token.UserRegion;
            var type = act.GetType();

            try
            {
                using (var db = new DzoContext())
                {
                    var ok = false;
                    if (type == typeof(ActBase))
                    {
                        ok = db.Acts.Add(act) != null;
                    }
                    if (type == typeof(ActCommon))
                    {
                        ok = db.CommonActs.Add(act as ActCommon ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(ActIndividual))
                    {
                        ok = db.IndividualActs.Add(act as ActIndividual ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(ActInpectationFl))
                    {
                        ok = db.ActsInspectionFl.Add(act as ActInpectationFl ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(ActInspectationUlIp))
                    {
                        ok = db.ActsInspectionUlIp.Add(act as ActInspectationUlIp ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(ActInspection))
                    {
                        ok = db.ActsInspection.Add(act as ActInspection ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(AgreementStatement))
                    {
                        ok = db.AgreementStatements.Add(act as AgreementStatement ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(AreaMeasurement))
                    {
                        ok = db.AreaMeasurements.Add(act as AreaMeasurement ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(CheckingJournal))
                    {
                        ok = db.CheckingJournals.Add(act as CheckingJournal ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(CitizensCheckPlan))
                    {
                        ok = db.CitizensCheckPlans.Add(act as CitizensCheckPlan ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(OrderInspectionUlIp))
                    {
                        ok = db.OrderInspectionsUlIp.Add(act as OrderInspectionUlIp ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(PhotoTable))
                    {
                        ok = db.PhotoTables.Add(act as PhotoTable ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(Protocol))
                    {
                        ok = db.Protocols.Add(act as Protocol ?? throw new InvalidOperationException()) != null;
                    }
                    if (type == typeof(Regulation))
                    {
                        ok = db.Regulations.Add(act as Regulation ?? throw new InvalidOperationException()) != null;
                    }
                    db.SaveChanges();
                    return(ok);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }