コード例 #1
0
        public HttpResponseMessage Put(int id, [FromBody] CoordinatorViewModel coordinatorViewModel)
        {
            try
            {
                var userId    = this.User.FindFirstValue(ClaimTypes.Name);
                var tempUsers = AutoMapper.Mapper.Map <Users>(coordinatorViewModel);
                tempUsers.CreatedDate = DateTime.Now;
                tempUsers.Createdby   = Convert.ToInt32(userId);
                tempUsers.Password    = EncryptLib.EncryptText(coordinatorViewModel.Password);
                _users.UpdateUsers(tempUsers);
                var tempCoordinator = AutoMapper.Mapper.Map <Coordinator>(coordinatorViewModel);
                _coordinator.UpdateCoordinator(tempCoordinator);
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                };

                return(response);
            }
            catch (Exception)
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.InternalServerError
                };
                return(response);
            }
        }
コード例 #2
0
        public HttpResponseMessage Post([FromBody] CoordinatorViewModel coordinator)
        {
            if (ModelState.IsValid)
            {
                var userId    = this.User.FindFirstValue(ClaimTypes.Name);
                var tempUsers = AutoMapper.Mapper.Map <Users>(coordinator);
                tempUsers.CreatedDate = DateTime.Now;
                tempUsers.Createdby   = Convert.ToInt32(userId);
                tempUsers.Password    = EncryptLib.EncryptText(coordinator.Password);
                _users.InsertUsers(tempUsers);
                var tempCoordinator = AutoMapper.Mapper.Map <Coordinator>(coordinator);
                tempCoordinator.UserId = tempUsers.UserId;
                _coordinator.InsertCoordinator(tempCoordinator);
                UsersInRoles usersInRoles = new UsersInRoles();
                usersInRoles.RoleId = 4;
                usersInRoles.UserId = tempCoordinator.UserId;
                _usersInRoles.AssignRole(usersInRoles);

                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.OK
                };

                return(response);
            }
            else
            {
                var response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest
                };

                return(response);
            }
        }
コード例 #3
0
        public IActionResult Create()
        {
            var model = new CoordinatorViewModel
            {
                HireDate = DateTime.Now,
            };

            return(View(model));
        }
コード例 #4
0
        public Task <IActionResult> Cancel(CoordinatorViewModel model)
        {
            var client = ClientFactory.CreateClient();
            var tasks  = new Task[model.Links.Count];
            var i      = 0;

            foreach (var link in model.Links)
            {
                Logger.LogInformation("Cancel {uri}.", link.Uri);
                tasks[i++] = client.DeleteAsync(link.Uri, HttpContext.RequestAborted);
            }

            Task.WaitAll(tasks, HttpContext.RequestAborted);

            var b = tasks.Cast <Task <HttpResponseMessage> >().Any(x => !x.Result.IsSuccessStatusCode);

            return(b ? Task.FromResult <IActionResult>(NotFound()) : Task.FromResult <IActionResult>(NoContent()));
        }
コード例 #5
0
        public async Task <IActionResult> Create(CoordinatorViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await this.userHelper.GetUserByEmailAsync(model.User.UserName);

                if (user == null)
                {
                    user = new User
                    {
                        FirstName   = model.User.FirstName,
                        LastName    = model.User.LastName,
                        PhoneNumber = model.User.PhoneNumber,
                        UserName    = model.User.UserName,
                        Email       = model.User.UserName,
                        Enrollment  = model.User.Enrollment
                    };
                }
                var result = await this.userHelper.AddUserAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await this.userHelper.AddUserToRoleAsync(user, "Coordinator");

                    var coordinator = new Coordinator
                    {
                        HireDate = model.HireDate,
                        User     = user
                    };

                    if (model.ImageFile != null)
                    {
                        coordinator.ImageUrl = await imageHelper.UploadImageAsync(
                            model.ImageFile, model.User.UserName, "Coordinator");
                    }
                    await coordinatorRepository.CreateAsync(coordinator);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(model));
        }
コード例 #6
0
        public async Task <object> CreateCoordinator(CoordinatorViewModel model)
        {
            Coordinator coordinator = new SimpleAutoMapper <Coordinator>().Map(model);

            try
            {
                if (coordinator.UserID == this.GetUserID())
                {
                    Response response = await _service.Create(coordinator);

                    return(this.SendResponse(response));
                }
                return(Forbid());
            }
            catch (Exception e)
            {
                Response.StatusCode = StatusCode(500).StatusCode;
                return(null);
            }
        }
コード例 #7
0
        public async Task <IActionResult> Create(CoordinatorViewModel model)
        {
            if (ModelState.IsValid)
            {
                var coordinator = new Coordinator
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName
                };
                if (model.ImageFile != null)
                {
                    coordinator.ImageUrl = await _imageHelper.UploadImageAsync(model.ImageFile, model.FullName, "Coordinator");
                }
                _context.Add(coordinator);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
コード例 #8
0
 /// <summary>
 /// Inicializacion de todos los objetos necesarios para el funcionamiento correcto del formulario
 /// </summary>
 public void startObjects()
 {
     _LiquHdVM = new Liquidation_HdrViewModel();
     ///
     _CoordinatorVM = new CoordinatorViewModel();
     ///
     _TransGuidesVM = new Transporters_GuidesViewModel();
     ///
     _packagesVM = new PackagesViewModel();
     ///
     _packDtlVM = new Packages_DtlViewModel();
     ///
     _ocPackDtl = new ObservableCollection <Packages_Dtl>();
     ///
     _CustomerType = "";
     ///
     //objGenerarTicket = new GenerarTicket();
     ///
     ///GridLiqInfo.DataContext = _LiquHdVM.getLiquidationHdr(_co, "25085");
     ///
 }
コード例 #9
0
        public async Task <object> UpdateCoordinator(CoordinatorViewModel model, int id)
        {
            Coordinator coordinator = new SimpleAutoMapper <Coordinator>().Map(model);

            coordinator.ID = id;
            try
            {
                if (await this.CheckPermissionToUpdateOrDeleteCoordinator(id))
                {
                    Response response = await _service.Update(coordinator);

                    return(this.SendResponse(response));
                }
                return(Forbid());
            }
            catch (Exception e)
            {
                Response.StatusCode = StatusCode(500).StatusCode;
                return(null);
            }
        }
コード例 #10
0
        // GET: Coordinators/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var coordinator = await _context.Coordinators.FindAsync(id);

            if (coordinator == null)
            {
                return(NotFound());
            }
            var model = new CoordinatorViewModel
            {
                Id        = coordinator.Id,
                FirstName = coordinator.FirstName,
                LastName  = coordinator.LastName,
                ImageUrl  = coordinator.ImageUrl
            };

            return(View(model));
        }
コード例 #11
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var coordinator = await coordinatorRepository.GetCoordinatorByIDWithUser(id.Value);

            if (coordinator == null)
            {
                return(NotFound());
            }

            var model = new CoordinatorViewModel
            {
                HireDate = coordinator.HireDate,
                Id       = coordinator.Id,
                ImageUrl = coordinator.ImageUrl,
                User     = coordinator.User
            };

            return(View(model));
        }
コード例 #12
0
        public async Task <IActionResult> Edit(CoordinatorViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await this.userHelper.GetUserByEmailAsync(model.User.UserName);

                if (user == null)
                {
                    return(NotFound(":("));
                }
                user.FirstName   = model.User.FirstName;
                user.LastName    = model.User.LastName;
                user.PhoneNumber = model.User.PhoneNumber;
                user.Enrollment  = model.User.Enrollment;

                var coordinator = await coordinatorRepository.GetCoordinatorByIDWithUser(model.Id);

                if (coordinator == null)
                {
                    return(NotFound(":("));
                }

                coordinator.HireDate = model.HireDate;
                coordinator.User     = user;

                if (model.ImageFile != null)
                {
                    coordinator.ImageUrl = await imageHelper.UploadImageAsync(
                        model.ImageFile, model.User.UserName, "Teacher");
                }
                await coordinatorRepository.UpdateAsync(coordinator);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
コード例 #13
0
        public async Task <IActionResult> Edit(CoordinatorViewModel model)
        {
            if (ModelState.IsValid)
            {
                var coordinator = await _context.Coordinators.FindAsync(model.Id);

                if (coordinator == null)
                {
                    return(NotFound());
                }

                coordinator.FirstName = model.FirstName;
                coordinator.LastName  = model.LastName;
                if (model.ImageFile != null)
                {
                    coordinator.ImageUrl = await _imageHelper.UploadImageAsync(model.ImageFile, model.FullName, "Coordinator");
                }
                _context.Update(coordinator);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(model));
        }
コード例 #14
0
        // GET: Coordinators/Create
        public IActionResult Create()
        {
            var model = new CoordinatorViewModel();

            return(View(model));
        }