public OperatorViewModel DestroyOperator(OperatorViewModel givenOperator)
        {
            this.Data.Operators.Delete(givenOperator.Id);
            this.Data.SaveChanges();

            return givenOperator;
        }
        public JsonResult DestroyOperator([DataSourceRequest] DataSourceRequest request, OperatorViewModel operatorModel)
        {
            var deletedOperator = operators.DestroyOperator(operatorModel);

            var loggedUserId = User.Identity.GetUserId();
            Base.CreateActivity(ActivityType.Delete, deletedOperator.Id.ToString(), ActivityTargetType.Operator, loggedUserId);

            return Json(new[] { operatorModel }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult CreateOperator([DataSourceRequest]  DataSourceRequest request, OperatorViewModel operatorModel)
        {
            if (operatorModel == null || !ModelState.IsValid)
            {
                return Json(new[] { operatorModel }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
            }

            var createdOperator = this.operators.CreateOperator(operatorModel);

            var loggedUserId = User.Identity.GetUserId();
            Base.CreateActivity(ActivityType.Create, createdOperator.Id.ToString(), ActivityTargetType.Operator, loggedUserId);

            operatorModel.Id = createdOperator.Id;

            return Json(new[] { operatorModel }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        public ActionResult Create(OperatorViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    operatorService.AddOrUpdate(model);
                    return RedirectToAction("Index")
                        .WithSuccess(string.Format("Operator \"{0} {1}\" has been added".TA(),
                            model.FirstName, model.LastName));
                }
                catch (ArgumentException err)
                {
                    ModelState.AddModelError(err.ParamName ?? string.Empty, err.Message);
                }
            }

            return View(model);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Transform OperatorViewModel <paramref name="updatedOperator"/> to Operator and update corresponding row in Operators table of DB
        /// </summary>
        /// <param name="updatedOperator">
        /// Should contain not null or empty Name and Id of existing Operators table entry.
        /// Name must be unique
        /// </param>
        /// <returns>Success, if transaction succesfull; !Success if not, Details contains error message if any</returns>
        public TransactionResultDTO Update(OperatorViewModel updatedOperator)
        {
            if (string.IsNullOrEmpty(updatedOperator.Name))
            {
                return new TransactionResultDTO()
                       {
                           Success = false, Details = "Operator name cannot be empty"
                       }
            }
            ;
            var check = unitOfWork.Operators.Get(o => o.Name == updatedOperator.Name).FirstOrDefault();

            if (check != null)
            {
                return new TransactionResultDTO()
                       {
                           Success = false, Details = "Operator name already exist"
                       }
            }
            ;
            var result = mapper.Map <Operator>(updatedOperator);

            try
            {
                unitOfWork.Operators.Update(result);

                unitOfWork.Save();
            }
            catch
            {
                return(new TransactionResultDTO()
                {
                    Success = false, Details = "Internal error"
                });
            }
            return(new TransactionResultDTO()
            {
                Success = true
            });
        }
Exemplo n.º 6
0
        private void OnlyMOperatorPage_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            OperatorViewModel vm = (OperatorViewModel)DataContext;

            if (vm == null)
            {
                return;
            }

            if (e.NewSize.Width >= 500)
            {
                vm.ThumbnailColWidth = 180;
            }
            else if (e.NewSize.Width >= 400)
            {
                vm.ThumbnailColWidth = 100;
            }
            else
            {
                vm.ThumbnailColWidth = 46;
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Edit(OperatorViewModel model)
        {
            if (ManagedYearPlan == null)
            {
                return(ActionIfNotChoosedManagedYearPlan());
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var @operator = await _operatorRepository.GetById(model.Id);

            @operator.FirstName   = model.FirstName;
            @operator.LastName    = model.LastName;
            @operator.ArimrNumber = model.ArimrNumber;
            await _operatorRepository.Update(@operator);

            TempData["message"] = "Zmiany zostały zapisane pomyślnie";
            return(View(model));
        }
Exemplo n.º 8
0
        public void Update_OperatorObject_ErrorResult()
        {
            OperatorViewModel test = new OperatorViewModel()
            {
                Name = "name"
            };

            mockUnitOfWork
            .Setup(m => m.Operators.Get(It.IsAny <Expression <Func <Operator, bool> > >(), null, ""))
            .Returns(new List <Operator>());
            mockUnitOfWork
            .Setup(n => n.Operators.Update(new Operator()
            {
                Name = "name"
            }));
            mockUnitOfWork
            .Setup(n => n.Save()).Throws(new Exception());

            var result = manager.Update(test);

            TestContext.WriteLine(result.Details);
            Assert.That(result.Success, Is.False);
        }
Exemplo n.º 9
0
        public JsonResult _OperatorEdit(OperatorViewModel input)
        {
            _context.Get <ApplicationUser>(d => d.Id == input.Id).FirstOrDefault().UpdateDatetime = _context.GetNzTime();
            var opteratorRoles = _context.Get <IdentityUserRole>(d => d.UserId == input.Id).ToList();

            foreach (var item in opteratorRoles)
            {
                if (input.RolePosted != null)
                {
                    if (!input.RolePosted.ids.Any(d => d == item.RoleId))
                    {
                        var entity = _context.Get <IdentityUserRole>(d => d.RoleId == item.RoleId && d.UserId == input.Id).FirstOrDefault();
                        _context.GetTranscaiton().Entry(entity).State = EntityState.Deleted;
                    }
                }
                else
                {
                    var entity = _context.Get <IdentityUserRole>(d => d.RoleId == item.RoleId && d.UserId == input.Id).FirstOrDefault();
                    _context.GetTranscaiton().Entry(entity).State = EntityState.Deleted;
                }
            }
            _context.SaveChange();
            if (input.RolePosted != null)
            {
                foreach (var item in input.RolePosted.ids)
                {
                    if (!opteratorRoles.Any(d => d.RoleId == item))
                    {
                        _context.AddOneEntity <IdentityUserRole>(new IdentityUserRole {
                            UserId = input.Id, RoleId = item
                        });
                    }
                }
            }
            return(Json("1", JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        private void SignIn_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(LoginTextBox.Text))
            {
                MessageBox.Show("Введите логин", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (string.IsNullOrEmpty(PasswordTextBox.Text))
            {
                MessageBox.Show("Введите пароль", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var operators = logic.Read(null);
            OperatorViewModel _operator = null;

            foreach (var oper in operators)
            {
                if (oper.Login == LoginTextBox.Text && oper.Password == PasswordTextBox.Text)
                {
                    _operator = oper;
                }
            }
            if (_operator != null)
            {
                App.Operator = _operator;
                var form = Container.Resolve <WindowMain>();
                form.Show();
                Close();
            }
            else
            {
                MessageBox.Show("Неверно введён логин или пароль", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
        }
        public OperatorViewModel CreateOperator(OperatorViewModel givenOperator)
        {
            if (givenOperator == null)
            {
                return null;
            }

            var newoperator = new Operator
            {
                Name = givenOperator.Name,
                Address = givenOperator.Address,
                PhoneNumber = givenOperator.PhoneNumber,
                Email = givenOperator.Email,
                Media = givenOperator.Media,
                IsVisible = givenOperator.IsVisible
            };

            this.Data.Operators.Add(newoperator);
            this.Data.SaveChanges();

            givenOperator.Id = newoperator.Id;

            return givenOperator;
        }
Exemplo n.º 12
0
        public User AddOrUpdate(OperatorViewModel model)
        {
            User user;

            if (!string.IsNullOrEmpty(model.Id))
            {
                user           = Find(model.Id);
                user.FirstName = model.FirstName;
                user.LastName  = model.LastName;
                user.Email     = model.Email;
                if (!string.IsNullOrEmpty(model.NewPassword))
                {
                    var passwordHash = userManager.PasswordHasher.HashPassword(model.NewPassword);
                    user.PasswordHash = passwordHash;
                }
            }
            else
            {
                user = Mapper.Map <User>(model);
            }

            if (string.IsNullOrEmpty(model.Id))
            {
                // Generate random password for new user if one is not specified
                if (string.IsNullOrEmpty(model.NewPassword))
                {
                    model.NewPassword = Guid.NewGuid().ToString();
                }

                IdentityResult result = userManager.Create(user, model.NewPassword);

                foreach (string error in result.Errors)
                {
                    throw new ArgumentException(error);
                }
            }

            if (model.Roles != null)
            {
                // Workaround bug in identity
                userManager.RemoveFromRoles(user.Id, userManager.GetRoles(user.Id).ToArray());

                // Add missing roles
                foreach (var role in model.Roles.Where(r => r.Contains("_")).ToList())
                {
                    var baseRole = role.Remove(role.IndexOf('_'));
                    if (!model.Roles.Contains(baseRole))
                    {
                        model.Roles.Add(baseRole);
                    }
                }

                userManager.AddToRole(user.Id, User.OPERATOR_ROLE);

                foreach (var role in model.Roles)
                {
                    if (!roleManager.RoleExists(role))
                    {
                        roleManager.Create(new IdentityRole(role));
                    }

                    if (!userManager.IsInRole(user.Id, role))
                    {
                        userManager.AddToRole(user.Id, role);
                    }
                }
            }

            db.SaveChanges();

            return(user);
        }
Exemplo n.º 13
0
        public ActionResult Create()
        {
            var model = new OperatorViewModel();

            return(View(model));
        }
        public OperatorViewModel UpdateOperator(OperatorViewModel givenOperator)
        {
            var operatorFromDb = this.Data.Operators
                .All()
              .FirstOrDefault(p => p.Id == givenOperator.Id);

            if (givenOperator == null || operatorFromDb == null)
            {
                return givenOperator;
            }

            operatorFromDb.Name = givenOperator.Name;
            operatorFromDb.Address = givenOperator.Address;
            operatorFromDb.PhoneNumber = givenOperator.PhoneNumber;
            operatorFromDb.Email = givenOperator.Email;
            operatorFromDb.Media = givenOperator.Media;
            operatorFromDb.IsVisible = givenOperator.IsVisible;

            var client = this.Data.Clients
                .All()
                .FirstOrDefault(c =>
                    (c.Marketing == givenOperator.Name) &&
                    (c.MarketingEmail == givenOperator.Email) &&
                    (c.MarketingPhone == givenOperator.PhoneNumber));

            if (client != null)
            {
                client.Marketing = givenOperator.Name;
                client.MarketingEmail = givenOperator.Email;
                client.MarketingPhone = givenOperator.PhoneNumber;
            }

            this.Data.SaveChanges();

            return givenOperator;
        }
Exemplo n.º 15
0
        public User AddOrUpdate(OperatorViewModel model)
        {
            User user;

            if (!string.IsNullOrEmpty(model.Id))
            {
                user = Find(model.Id);
                user.FirstName = model.FirstName;
                user.LastName = model.LastName;
                user.Email = model.Email;
                if (!string.IsNullOrEmpty(model.NewPassword))
                {
                    var passwordHash = userManager.PasswordHasher.HashPassword(model.NewPassword);
                    user.PasswordHash = passwordHash;
                }
            }
            else
            {
                user = Mapper.Map<User>(model);
            }

            if (string.IsNullOrEmpty(model.Id))
            {
                // Generate random password for new user if one is not specified
                if (string.IsNullOrEmpty(model.NewPassword))
                    model.NewPassword = Guid.NewGuid().ToString();

                IdentityResult result = userManager.Create(user, model.NewPassword);

                foreach (string error in result.Errors)
                {
                    throw new ArgumentException(error);
                }
            }

            if (model.Roles != null)
            {
                // Workaround bug in identity
                userManager.RemoveFromRoles(user.Id, userManager.GetRoles(user.Id).ToArray());

                // Add missing roles
                foreach (var role in model.Roles.Where(r => r.Contains("_")).ToList())
                {
                    var baseRole = role.Remove(role.IndexOf('_'));
                    if (!model.Roles.Contains(baseRole))
                        model.Roles.Add(baseRole);
                }

                userManager.AddToRole(user.Id, User.OPERATOR_ROLE);

                foreach (var role in model.Roles)
                {
                    if (!roleManager.RoleExists(role))
                        roleManager.Create(new IdentityRole(role));

                    if (!userManager.IsInRole(user.Id, role))
                        userManager.AddToRole(user.Id, role);
                }
            }

            db.SaveChanges();

            return user;
        }
Exemplo n.º 16
0
        public ActionResult Create()
        {
            var model = new OperatorViewModel();

            return View(model);
        }