Ejemplo n.º 1
0
        public async Task <ActionResult> GetBusinessCard(UIBusinessCard UserBusinessCard, HttpPostedFileBase uploadImage)
        {
            ApplicationUser user = await GetCurrentUser();

            if (ModelState.IsValid)
            {
                //конфигурация маппера
                Mapper.Initialize(cfg => cfg.CreateMap <UIBusinessCard, BusinessCard>());
                //сопоставление
                BusinessCard DBUserBusinessCard = Mapper.Map <UIBusinessCard, BusinessCard>(UserBusinessCard);
                DBUserBusinessCard.User = user;
                byte[] imageData = null;
                // считываем переданный файл в массив байтов
                using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                {
                    imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                }
                // установка массива байтов
                DBUserBusinessCard.Logo = imageData;
                user.BusinessCard       = DBUserBusinessCard;
                db.Users.Attach(user);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index", "Vacancies"));
            }
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> EditBusinessCard(UIBusinessCard UserBusinessCard, HttpPostedFileBase uploadImage)
        {
            if (ModelState.IsValid)
            {
                BusinessCard DBUserBusinessCard = await db.BusinessCards.FindAsync(UserBusinessCard.BusinessCardId);

                //конфигурация маппера
                Mapper.Initialize(cfg => cfg.CreateMap <UIBusinessCard, BusinessCard>().ForMember(d => d.Logo, (options) => options.Ignore()));
                //сопоставление
                Mapper.Map(UserBusinessCard, DBUserBusinessCard);
                ApplicationUser user = await GetCurrentUser();

                DBUserBusinessCard.User = user;
                if (uploadImage != null)
                {
                    byte[] imageData = null;
                    // считываем переданный файл в массив байтов
                    using (var binaryReader = new BinaryReader(uploadImage.InputStream))
                    {
                        imageData = binaryReader.ReadBytes(uploadImage.ContentLength);
                    }
                    // установка массива байтов
                    DBUserBusinessCard.Logo = imageData;
                }
                db.Entry(DBUserBusinessCard).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("GetBusinessCard"));
            }
            return(View());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> EditBusinessCard(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BusinessCard DBUserBusinessCard = await db.BusinessCards.FindAsync(id);

            if (DBUserBusinessCard == null)
            {
                return(HttpNotFound());
            }
            //конфигурация маппера
            Mapper.Initialize(cfg => cfg.CreateMap <BusinessCard, UIBusinessCard>());
            //сопоставление
            UIBusinessCard UserBusinessCard = Mapper.Map <BusinessCard, UIBusinessCard>(DBUserBusinessCard);

            return(View(UserBusinessCard));
        }
Ejemplo n.º 4
0
        // GET
        public async Task <ActionResult> GetBusinessCard()
        {
            ApplicationUser user = await GetCurrentUser();

            UIBusinessCard UserBusinessCard   = new UIBusinessCard();
            var            DBUserBusinessCard = user.BusinessCard;

            if (DBUserBusinessCard != null)
            {
                //конфигурация маппера
                Mapper.Initialize(cfg => cfg.CreateMap <BusinessCard, UIBusinessCard>());
                //сопоставление
                UserBusinessCard = Mapper.Map <BusinessCard, UIBusinessCard>(DBUserBusinessCard);
                return(View("ShowBusinessCard", UserBusinessCard));
            }
            else
            {
                return(View());
            }
        }