public ActionResult DeleteInput(int?activityInputId, int activityId)
        {
            if (activityInputId != null)
            {
                try
                {
                    //Models.ActivityInput AI = DB.ActivityInputs.Find(visitInputId);


                    // Do we need this?
                    //AI.Activity = null;

                    //for (int i = 0; i < AI.ActivityInputDatas.Count; i++)
                    //{
                    //    DB.ActivityInputDatas.Remove(AI.ActivityInputDatas.ElementAt(i));
                    //}


                    //DB.ActivityInputs.Remove(AI);

                    Models.ActivityActivityInput AAI = DB.ActivityActivityInputs.FirstOrDefault(x => x.Activity.ActivityId == activityId && x.ActivityInput.ActivityInputId == activityInputId);

                    AAI.Active = false;

                    DB.SaveChanges();
                }
                catch (Exception e)
                {
                    int x = 10;
                }
            }

            return(RedirectToAction("Index", new { activityId = activityId }));
        }
Esempio n. 2
0
        public ActionResult DeleteInput(int?visitInputId, int serviceId)
        {
            if (visitInputId != null)
            {
                try
                {
                    //Models.ActivityInput AI = DB.ActivityInputs.Find(visitInputId);


                    // Do we need this?
                    //AI.Activity = null;

                    //for (int i = 0; i < AI.ActivityInputDatas.Count; i++)
                    //{
                    //    DB.ActivityInputDatas.Remove(AI.ActivityInputDatas.ElementAt(i));
                    //}


                    //DB.ActivityInputs.Remove(AI);

                    Models.Activity        Act = DB.Activities.Find(visitInputId);
                    Models.ServiceActivity SA  = DB.ServiceActivities.Where(sa => sa.Service.ServiceId == serviceId && sa.Activity.ActivityId == visitInputId).FirstOrDefault();

                    SA.Active = false;

                    DB.SaveChanges();
                }
                catch (Exception e)
                {
                    int x = 10;
                }
            }

            return(RedirectToAction("Index", new { serviceId = serviceId }));
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "Id,Name,Beschreibung")] Anwendung anwendung)
        {
            if (ModelState.IsValid)
            {
                db.Anwendung.Add(anwendung);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(anwendung));
        }
Esempio n. 4
0
        public ActionResult Create([Bind(Include = "Id,Name,Sensibel,PK")] Feld feld, int?id)
        {
            if (ModelState.IsValid)
            {
                db.Feld.Add(feld);
                db.SaveChanges();
                return(RedirectToAction("Edit", "Datentypen", new { Id = id }));
            }

            return(View(feld));
        }
Esempio n. 5
0
        public ActionResult Create([Bind(Include = "Id,Name,Beschreibung")] Datentyp datentyp)
        {
            if (ModelState.IsValid)
            {
                db.Datentyp.Add(datentyp);
                db.SaveChanges();
                return(RedirectToAction("Edit", new { Id = datentyp.Id }));
            }

            return(View(datentyp));
        }
Esempio n. 6
0
        public string NurseReplacement(int id1)
        {
            try
            {
                Employee         Nurse1 = DB.Employees.Find(id1);
                int              tmpId  = id1;
                List <WorkOrder> WO     = DB.WorkOrders.Where(x => x.Nurse.EmployeeId == Nurse1.EmployeeId).ToList();
                //List<Visit> visits = new List<Visit>();
                foreach (var workorder in WO)
                {
                    foreach (var visit in workorder.Visits)
                    {
                        if (visit.Done == false)
                        {
                            Employee Nurse2 = DB.Employees.FirstOrDefault(x => x.EmployeeId != id1 && x.JobTitle.Title == JobTitle.HealthNurse && x.Absences.All(abs => abs.DateStart > visit.DateConfirmed || abs.DateEnd < visit.DateConfirmed));
                            if (Nurse2 == null)
                            {
                                return("Neuspešno! Na dan " + visit.DateConfirmed.ToString("dd. MM. yyyy") + "ni ustrezne zamenjave!");
                            }
                            visit.NurseReplacement = Nurse2;
                        }
                    }
                }
                List <Visit> visits = DB.Visits.Where(x => x.Done == false && x.NurseReplacement != null && x.NurseReplacement.EmployeeId == tmpId).ToList();
                foreach (var visit in visits)
                {
                    Employee Nurse2 = DB.Employees.FirstOrDefault(x => x.EmployeeId != id1 && x.JobTitle.Title == JobTitle.HealthNurse && x.Absences.All(abs => abs.DateStart > visit.DateConfirmed || abs.DateEnd < visit.DateConfirmed));
                    if (Nurse2 == null)
                    {
                        return("Neuspešno! Na dan " + visit.DateConfirmed.ToString("dd. MM. yyyy") + "ni ustrezne zamenjave!");
                    }
                    if (Nurse2.EmployeeId == visit.WorkOrder.Nurse.EmployeeId)
                    {
                        var forceLoad = visit.NurseReplacement; //Aleluja
                        visit.NurseReplacement = null;          // Now EF knows something has changed
                    }
                    else
                    {
                        visit.NurseReplacement = Nurse2;
                    }
                }


                DB.SaveChanges();

                return("");
            }
            catch (Exception e)
            {
                return("Hujša napaka");
            }
        }
        public ActionResult EmailActivation(string userEmail, string emailCode)
        {
            Models.User u = DB.Users.FirstOrDefault(us => us.Email == userEmail);

            if (u != null && u.Active == false && u.EmailCode == emailCode && u.EmailExpire > DateTime.Now)
            {
                u.Active        = true;
                Session["user"] = u;
                DB.SaveChanges();
            }

            return(Redirect("/"));
        }
Esempio n. 8
0
        public ActionResult EditListUser(tbl_1_User user)
        {
            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("ViewListUser"));
            }

            SelectList roles = new SelectList(db.tbl_2_Roles, "RoleId", "RoleName");

            ViewBag.tbl_2_Roles = roles;

            return(View(user));
        }
        public static void ByAddWithNoDetect(int count)
        {
            DatabaseOps.ClearPrimaryTable();

            var entities = EntityGenerator.Generate(count);

            using (var context = new EntityDataModel())
            {
                var stopwatch = new Stopwatch();

                stopwatch.Start();

                context.Configuration.AutoDetectChangesEnabled = false;

                entities.ForEach(entity => context.Orders.Add(entity));

                context.Configuration.AutoDetectChangesEnabled = true;

                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("NoDetect({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }
        public ActionResult ConfirmVisit(VisitPlannerViewModel vm)
        {
            if (vm.PlanDate.Value.Date >= DateTime.Now.Date && vm.HiddenVisitId != null)
            {
                Models.Visit visit = DB.Visits.Find(vm.HiddenVisitId);

                if (visit != null)
                {
                    visit.DateConfirmed = vm.PlanDate.Value;
                    visit.Confirmed     = true;
                    DB.SaveChanges();
                }
            }

            return(RedirectToAction("Index", "VisitPlanner", null));
        }
Esempio n. 11
0
 public OperationResult AddNewCustomer(Customer customer)
 {
     if (DatabaseContext.Customers.All(c => c.CustomerId != customer.CustomerId))
     {
         DatabaseContext.Customers.Add(customer);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
Esempio n. 12
0
 public OperationResult AddNewProduct(Product product)
 {
     if (DatabaseContext.Products.All(p => p.ProductId != product.ProductId))
     {
         DatabaseContext.Products.Add(product);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
Esempio n. 13
0
 public OperationResult AddNewProductCategory(ProductCategory productCategory)
 {
     if (DatabaseContext.ProductCategories.All(pc => pc.ProductCategoryId == productCategory.ProductCategoryId))
     {
         DatabaseContext.ProductCategories.Add(productCategory);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
Esempio n. 14
0
 public OperationResult AddNewOrder(Order order)
 {
     if (DatabaseContext.Orders.All(o => o.OrderId != order.OrderId))
     {
         DatabaseContext.Orders.Add(order);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
Esempio n. 15
0
 public OperationResult AddNewToppingCategory(ToppingCategory toppingCategory)
 {
     if (DatabaseContext.ToppingCategories.All(tc => tc.ToppingCategoryId != toppingCategory.ToppingCategoryId))
     {
         DatabaseContext.ToppingCategories.Add(toppingCategory);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
 public OperationResult AddNewEmployee(Employee employee)
 {
     if (DatabaseContext.Employees.All(e => e.EmployeeId != employee.EmployeeId))
     {
         DatabaseContext.Employees.Add(employee);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
Esempio n. 17
0
 public OperationResult AddNewTopping(Topping topping)
 {
     if (DatabaseContext.Toppings.All(t => t.ToppingId != topping.ToppingId))
     {
         DatabaseContext.Toppings.Add(topping);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
 public OperationResult AddNewAllergen(Allergen allergen)
 {
     if (DatabaseContext.Allergens.All(al => al.AllergenId != allergen.AllergenId))
     {
         DatabaseContext.Allergens.Add(allergen);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
Esempio n. 19
0
 public OperationResult AddNewCustomizedProduct(CustomizedProduct customizedProduct)
 {
     if (DatabaseContext.CustomizedProducts.All(cp =>
                                                cp.CustomizedProductId != customizedProduct.CustomizedProductId))
     {
         DatabaseContext.CustomizedProducts.Add(customizedProduct);
         DatabaseContext.SaveChanges();
         return(new OperationResult {
             IsSucceeded = true
         });
     }
     else
     {
         return(new OperationResult {
             IsSucceeded = false
         });
     }
 }
        public ActionResult Delete(int workorderId)
        {
            bool CanDelete = true;

            Models.WorkOrder WO = DB.WorkOrders.Find(workorderId);

            if (WO != null)
            {
                #region Check

                Employee current = (Session["user"] as Models.User).Employee;

                // IF doctor or head
                if (current.JobTitle.Title == JobTitle.Doctor || current.JobTitle.Title == JobTitle.Head)
                {
                    // If I created this workroder
                    if (WO.Issuer.EmployeeId == current.EmployeeId)
                    {
                        // If WO has any done vists
                        if (WO.Visits.Any(v => v.DateConfirmed < DateTime.Now || v.Done))
                        {
                            // Can't delete
                            CanDelete = false;
                        }
                        else
                        {
                            // Can delete
                            CanDelete = true;
                        }
                    }
                    else
                    {
                        CanDelete = false;
                    }
                }
                else
                {
                    CanDelete = false;
                }

                #endregion

                if (CanDelete)
                {
                    DB.Visits.RemoveRange(WO.Visits);
                    DB.PatientWorkOrders.RemoveRange(WO.PatientWorkOrders);
                    DB.BloodSamples.RemoveRange(WO.BloodSamples);
                    DB.MaterialWorkOrders.RemoveRange(WO.MaterialWorkOrders);
                    DB.MedicineWorkOrders.RemoveRange(WO.MedicineWorkOrders);
                    DB.WorkOrders.Remove(WO);
                    DB.SaveChanges();
                }
            }

            return(Index(null));
        }
Esempio n. 21
0
        public override void CreateRole(string roleName)
        {
            tbl_2_Roles newRole = new tbl_2_Roles()
            {
                RoleName = roleName
            };
            EntityDataModel db = new EntityDataModel();

            db.tbl_2_Roles.Add(newRole);
            db.SaveChanges();
        }
Esempio n. 22
0
        public void Delete(int id)
        {
            Club club = db.Clubs.Find(id);

            db.Clubs.Remove(club);
            db.SaveChanges();
            //var removeClub = GetAll().SingleOrDefault(c => c.Id == club.Id);
            //removeClub.
            //var _club = _ClubContext.Clubs.Remove(club);
            //_ClubContext.SaveChanges();
            //return _club;
        }
Esempio n. 23
0
        public ActionResult Delete(int?absenceId)
        {
            if (absenceId == null)
            {
                return(Index());
            }
            Absence          a     = DB.Absences.Where(x => x.AbsenceId == absenceId).FirstOrDefault();
            Employee         Nurse = a.AbsenceNurse;
            List <WorkOrder> WO    = DB.WorkOrders.Where(x => x.Nurse.EmployeeId == Nurse.EmployeeId).ToList();

            for (int i = 0; i < WO.Count; i++)
            {
                int       tmp = WO.ElementAt(i).WorkOrderId;
                WorkOrder w   = DB.WorkOrders.FirstOrDefault(x => x.WorkOrderId == tmp);
                for (int j = 0; j < w.Visits.Count; j++)
                {
                    Visit vi = DB.Visits.Find(w.Visits.ElementAt(j).VisitId);
                    if (vi.DateConfirmed >= DateTime.Now && !vi.Done && vi.DateConfirmed >= a.DateStart && vi.DateConfirmed <= a.DateEnd)
                    {
                        var forceLoad = vi.NurseReplacement; //Aleluja
                        vi.NurseReplacement = null;          // Now EF knows something has changed
                        DB.SaveChanges();
                    }
                }
            }
            DB.Absences.Remove(a);
            DB.SaveChanges();


            //ervm.AllNurses = DB.Employees.Where(x => x.Title == Employee.JobTitle.HealthNurse).ToList();
            EndReplacementViewModel ervm = new EndReplacementViewModel();

            ervm.AllNurses   = DB.Employees.Where(x => x.JobTitle.Title == JobTitle.HealthNurse && x.User.Active == true).ToList();
            ervm.Absences    = new List <Absence>();
            ervm.CanDelete   = new List <bool>();
            ervm.ViewMessage = "Konec nadomeščanja uspešna";
            ervm.NurseId     = Nurse.FullNameWithCode;
            return(EndReplacement(ervm));
        }
 public static void ClearDatabase(EntityDataModel model)
 {
     model.Allergens.RemoveRange(model.Allergens);
     model.Customers.RemoveRange(model.Customers);
     model.CustomizedProducts.RemoveRange(model.CustomizedProducts);
     model.Orders.RemoveRange(model.Orders);
     model.Employees.RemoveRange(model.Employees);
     model.EmployeeCategories.RemoveRange(model.EmployeeCategories);
     model.TimeIntervals.RemoveRange(model.TimeIntervals);
     model.Toppings.RemoveRange(model.Toppings);
     model.ToppingCategories.RemoveRange(model.ToppingCategories);
     model.Products.RemoveRange(model.Products);
     model.ProductCategories.RemoveRange(model.ProductCategories);
     model.SaveChanges();
 }
        public ActionResult ChangePassword(ChangePasswordViewModel cpvm)
        {
            try {
                if (cpvm.Password1.IsNullOrWhiteSpace() ||
                    cpvm.Password2.IsNullOrWhiteSpace() ||
                    cpvm.OldPassword.IsNullOrWhiteSpace())
                {
                    cpvm.ViewMessage = "Ponovno preverite vnešene podatke!";
                    return(Form(cpvm));
                }

                if (!cpvm.Password1.Any(c => char.IsDigit(c)))
                {
                    cpvm.ViewMessage = "Geslo mora vsebovati vsaj eno številko!";
                    return(Form(cpvm));
                }

                if (cpvm.Password1 != cpvm.Password2)
                {
                    cpvm.ViewMessage = "Gesli se ne ujemata!";
                    return(Form(cpvm));
                }



                Models.User tmp  = (Models.User)Session["user"];
                Models.User user = DB.Users.FirstOrDefault(u => u.UserId == tmp.UserId);

                if (cpvm.OldPassword != user.Password)
                {
                    cpvm.ViewMessage = "Staro geslo ni pravilno!";
                    return(Form(cpvm));
                }

                TempData["email"] = user.Email;
                user.Password     = cpvm.Password1;
                DB.SaveChanges();
                cpvm.ViewMessage = "qwe";
                Session["user"]  = null;
                return(RedirectToAction("Index", "Login"));
                //return Form(cpvm);
            }
            catch (Exception e)
            {
                cpvm.ViewMessage = "Prišlo je do hujše napake!";
                return(Form(cpvm));
            }
        }
        public static void ByRange(int count)
        {
            DatabaseOps.ClearPrimaryTable();

            var entities = EntityGenerator.Generate(count);

            using (var context = new EntityDataModel())
            {
                var stopwatch = new Stopwatch();

                stopwatch.Start();

                context.Orders.AddRange(entities);
                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("Range({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }
Esempio n. 27
0
        //
        // POST: /PictureManagement/Create

        //[HttpGet]
        public ActionResult AddPicture(tbl_14_WorksOfArt pict, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid && uploadImage != null)
            {
                byte[] imageData = null;
                // считываем переданный файл в массив байтов
                using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                }
                // установка массива байтов
                pict.PicturePhoto = imageData;

                samdb.tbl_14_WorksOfArt.Add(pict);
                samdb.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(pict));
        }
        public static void BySaveChanges(int count)
        {
            DatabaseOps.ClearPrimaryTable();
            Insert.BySqlBulkCopy(count, false);

            using (var context = new EntityDataModel())
            {
                var entities = context.Orders.ToList();

                entities.ForEach(entity => entity.Date = DateTime.Now.AddYears(666));

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("SaveChanges({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }
        public static void ByAdd(int count)
        {
            DatabaseOps.ClearPrimaryTable();

            //Создаем нужное количество объектов для добавления в контекст
            var entities = EntityGenerator.Generate(count);

            using (var context = new EntityDataModel())
            {
                var stopwatch = new Stopwatch();

                stopwatch.Start();

                entities.ForEach(entity => context.Orders.Add(entity));

                context.SaveChanges();

                stopwatch.Stop();

                Console.WriteLine("Add({0}) = {1} s", count, stopwatch.Elapsed.TotalSeconds);
            }
        }
Esempio n. 30
0
        public IHttpActionResult PutUsuario(int id, UsuarioDTO dto)
        {
            Usuario usuario = new Usuario();

            if (id != dto.Id_usuario)
            {
                return(BadRequest());
            }

            try
            {
                var updatedUser = dataModel.Usuario.SingleOrDefault(x => x.Id_usuario == id);

                updatedUser.Nome            = dto.Nome;
                updatedUser.Login           = dto.Login;
                updatedUser.Senha           = dto.Senha;
                updatedUser.Fk_perfil       = dto.Fk_perfil;
                updatedUser.Estado          = dto.Estado;
                updatedUser.Cidade          = dto.Cidade;
                updatedUser.Email           = dto.Email;
                updatedUser.Telefone        = dto.Telefone;
                updatedUser.Data_nascimento = dto.Data_nascimento;

                dataModel.Entry(updatedUser).State = EntityState.Modified;
                dataModel.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UsuarioExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(StatusCode(HttpStatusCode.NoContent));
        }