Exemplo n.º 1
0
        public async Task <ActionResult> Create(Address address)
        {
            if (ModelState.IsValid)
            {
                var personnelId = UserPersonnelId;
                var personnel   = await _personnelBusinessService.RetrievePersonnel(personnelId);

                if (personnel == null)
                {
                    return(RedirectToAction("Login", "Account"));
                }
                var result = await _addressBusinessService.CreateAddress(personnel.Entity.PersonnelId, address);

                if (result.Succeeded)
                {
                    return(this.JsonNet(string.Empty));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error);
                }
            }
            return(this.JsonNet(
                       ModelState.Values.Where(e => e.Errors.Count > 0)
                       .Select(e => e.Errors.Select(d => d.ErrorMessage).FirstOrDefault())
                       .Distinct()));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> UploadPhoto(int personnelId)
        {
            //if (!await AuthorizationService.AuthorizeAsync((ClaimsPrincipal)User, personnelId, Policies.Resource.Personnel.ToString()))
            //    return HttpForbidden();

            try
            {
                var getPersonnelResult = await _personnelBusinessService.RetrievePersonnel(personnelId);

                if (!getPersonnelResult.Succeeded)
                {
                    return(HttpNotFound(string.Join(";", getPersonnelResult.Errors)));
                }

                var person = getPersonnelResult.Entity;

                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        //var personnelProfile = await _personnelDocumentBusinessService.RetrievePersonnelProfileImage(getPersonnelResult.Entity.PersonnelId);
                        //if (personnelProfile.Succeeded)
                        //    await _documentsBusinessService.DeleteDocument(new List<Guid> { personnelProfile.Entity.DocumentGuid.Value });

                        byte[] fileData = null;
                        using (var binaryReader = new BinaryReader(file.InputStream))
                        {
                            fileData = binaryReader.ReadBytes(file.ContentLength);
                        }
                        var documentMeta = new Document()
                        {
                            Content       = fileData,
                            Description   = string.Format("{0} Profile Image", person.FullName),
                            FileName      = file.FileName.Split('\\').Last() + ".png",
                            PersonnelName = person.FullName,
                            CreatedBy     = User.Identity.Name,
                            PersonnelId   = person.PersonnelId.ToString(),
                            Category      = Business.Enum.DocumentCategory.DrivingSchoolProfile.ToString(),
                            CategoryId    = (int)Business.Enum.DocumentCategory.DrivingSchoolProfile
                        };

                        var result = await _documentsBusinessService.CreateDocument(documentMeta);

                        if (!result.Succeeded)
                        {
                            return(this.JsonNet("SaveError"));
                        }
                    }
                }
                return(this.JsonNet(""));
            }
            catch (Exception ex)
            {
                return(this.JsonNet(ex));
            }
        }
        public async Task <ActionResult> Profile(bool?profileUpdated)
        {
            var id = UserPersonnelId;

            if (User.IsPersonnel() && !await AuthorizationService.AuthorizeAsync((ClaimsPrincipal)User, id, Policies.Resource.Personnel.ToString()))
            {
                return(HttpForbidden());
            }

            if (id == 0)
            {
                return(RedirectToAction("Login", "Account"));
            }

            var personnel = await _personnelBusinessService.RetrievePersonnel(id);

            if (personnel == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new PersonnelProfileViewModel
            {
                Personnel      = personnel.Entity,
                PersonnelId    = personnel.Entity.PersonnelId,
                ProfileUpdated = profileUpdated ?? false
                                 //Permissions = EgharpayBusinessService.RetrievePersonnelPermissions(isAdmin, UserOrganisationId, UserPersonnelId, id),
                                 //PhotoBytes = EgharpayBusinessService.RetrievePhoto(organisationId, id)
            };

            if (User.IsSeller())
            {
                var seller = await _sellerBusinessService.RetrieveSellerByPersonnelId(personnel.Entity.PersonnelId);

                viewModel.IsSellerApproved = seller.ApprovalStateId == (int)SellerApprovalState.Approved;
            }

            return(View(viewModel));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Profile(int id)
        {
            var personnel = await _personnelBusinessService.RetrievePersonnel(UserOrganisationId, id);

            if (personnel == null)
            {
                return(HttpNotFound());
            }
            var isAdmin = User.IsInAnyRoles("Admin");

            if (!isAdmin)
            {
            }
            var viewModel = new PersonnelProfileViewModel
            {
                Personnel = personnel,
                //Permissions = EgharpayBusinessService.RetrievePersonnelPermissions(isAdmin, UserOrganisationId, UserPersonnelId, id),
                //PhotoBytes = EgharpayBusinessService.RetrievePhoto(organisationId, id)
            };

            return(View(viewModel));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> UploadSelfie(int?id, string tagLine)
        {
            try
            {
                var getPersonnelResult = await _personnelBusinessService.RetrievePersonnel(id.Value);

                if (!getPersonnelResult.Succeeded)
                {
                    return(HttpNotFound(string.Join(";", getPersonnelResult.Errors)));
                }

                var personnel = getPersonnelResult.Entity;

                if (Request.Files.Count > 0)
                {
                    var file = Request.Files[0];

                    if (file != null && file.ContentLength > 0)
                    {
                        byte[] fileData = null;
                        using (var binaryReader = new BinaryReader(file.InputStream))
                        {
                            fileData = binaryReader.ReadBytes(file.ContentLength);
                        }
                        var documentMeta = new Document()
                        {
                            Content       = fileData,
                            Description   = tagLine == "null" ? string.Empty : tagLine,
                            FileName      = file.FileName.Split('\\').Last() + ".png",
                            PersonnelName = personnel.FullName,
                            CreatedBy     = User.Identity.GetUserId(),
                            PersonnelId   = personnel.PersonnelId.ToString(),
                            Category      = Business.Enum.DocumentCategory.Selfie.ToString(),
                            CategoryId    = (int)Business.Enum.DocumentCategory.Selfie
                        };

                        var result = await _personnelBusinessService.UploadDocument(documentMeta, personnel.PersonnelId);

                        if (!result.Succeeded)
                        {
                            return(this.JsonNet("SaveError"));
                        }
                    }
                }
                return(this.JsonNet(""));
            }
            catch (Exception ex)
            {
                return(this.JsonNet("SaveError"));
            }
        }
Exemplo n.º 6
0
        public async Task <ActionResult> List(Paging paging, List <OrderBy> orderBy)
        {
            try
            {
                var personnelId   = UserPersonnelId;
                var personnel     = _personnelBusinessService.RetrievePersonnel(UserPersonnelId);
                var personnelData = personnel.Result.Entity;
                //var personnelData = _personnelBusinessService.RetrievePersonnels(null, null).Result.Items.FirstOrDefault();
                var isSeller = personnelData.IsSeller;
                var data     = isSeller ? await _orderBusinessService.RetrieveSellerOrders(e => e.SellerPersonnelId == personnelData.PersonnelId, orderBy, paging) : await _orderBusinessService.RetrieveSellerOrders(e => e.BuyerPersonnelId == personnelData.PersonnelId, orderBy, paging);

                return(this.JsonNet(data));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }