예제 #1
0
        public async Task <IActionResult> Create(ItemViewModel item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var Item = mapper.Map <Item>(item);
                    Item.ImgUrl    = uploadImages.AddImage(item.File);
                    Item.Sorting   = _context.Items.Count() + 1;
                    Item.ShortLink = RandomURL.GetURL();
                    Item.Date      = DateTime.Now.ToShortDateString();
                    if (Item.RatingValues == null)
                    {
                        Item.RatingValues = 0;
                    }
                    if (Item.RatingCount == null)
                    {
                        Item.RatingCount = 0;
                    }

                    if (item.RaitingValue != 0)
                    {
                        Item.RatingCount++;
                        Item.RatingValues += item.RaitingValue;
                    }



                    _context.Add(Item);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["CityId"]   = new SelectList(_context.Cities, "Id", "Name", item.CityId);
                ViewData["MemberId"] = new SelectList(supliers(), "Id", "FullName", item.MemberId);
                ViewData["UnitId"]   = new SelectList(units(), "Id", "Name");


                return(View(item));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
예제 #2
0
        public IActionResult ConvertFiles(IFormFile[] files)
        {
            if (files.Length == 0)
            {
                return(BadRequest());
            }

            using (MemoryStream documentStream = new MemoryStream())
            {
                Document  document = new Document(PageSize.A4, 25f, 25f, 25f, 25f);
                PdfWriter writer   = PdfWriter.GetInstance(document, documentStream);

                document.Open();
                PdfContentByte contentByte = writer.DirectContent;


                foreach (IFormFile file in files)
                {
                    document.NewPage();
                    Image image = Image.GetInstance(file.OpenReadStream());
                    image.SetAbsolutePosition(200, 400);
                    image.ScaleAbsolute(300, 300);

                    contentByte.AddImage(image);
                }

                document.Close();

                byte[] bytes = documentStream.GetBuffer();
                string uri   = RandomURL.GetURL().ToString();


                if (!AddPdfToDb(uri, bytes))
                {
                    return(BadRequest());
                }

                Response.Headers.Add("uri", uri);
                return(Ok());
            }
        }
예제 #3
0
        public async Task <IActionResult> Create(MemberViewModel member)
        {
            try
            {
                member.ItemsCount = 0;
                if (ModelState.IsValid)
                {
                    var Member = mapper.Map <Member>(member);
                    Member.ImgUrl         = uploadImages.AddImage(member.File);
                    Member.ActivationCode = RandomURL.GetURL();
                    _context.Add(Member);
                    var created = await _context.SaveChangesAsync();

                    if (created >= 0)
                    {
                        //add Customer to role
                        var supplier = _context.Members.ToList().LastOrDefault();
                        var role     = _context.Roless.FirstOrDefault(r => r.Name == "Customer");
                        if (role != null && supplier != null)
                        {
                            MemberRole SupplierRole = new MemberRole();
                            SupplierRole.MemberId = supplier.Id;
                            SupplierRole.RoleId   = role.Id;
                            _context.MemberRoles.Add(SupplierRole);
                            _context.SaveChanges();
                        }
                    }



                    return(RedirectToAction(nameof(Index)));
                }
                ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", member.CityId);
                return(View(member));
            }
            catch
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
예제 #4
0
        public IActionResult ClientRegister(ClientRegisterViewModel client)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var Client = (from c in _context.Members
                                  from r in _context.Roless
                                  from cr in _context.MemberRoles
                                  where cr.RoleId == r.Id && cr.MemberId == c.Id && r.Name == "Customer" && c.Phone == client.UserPhone
                                  select c).FirstOrDefault();

                    if (Client != null)
                    {
                        ModelState.AddModelError("UserPhone", "تم تسجيل هذا الحساب مسبقا");
                        return(View(client));
                    }

                    var Member = new Member();
                    Member.FullName = client.UserName;
                    Member.Phone    = client.UserPhone;
                    Member.Password = RandomURL.GetURL();
                    Member.CityId   = client.CityId;
                    Member.State    = true;


                    _context.Add(Member);
                    var created  = _context.SaveChanges();
                    var Customer = new Member();
                    if (created > 0)
                    {
                        //add Customer to role
                        Customer = _context.Members.ToList().FirstOrDefault(c => c.Phone == client.UserPhone);
                        var role = _context.Roless.FirstOrDefault(r => r.Name == "Customer");
                        if (role != null && Customer != null)
                        {
                            MemberRole CustomerRole = new MemberRole();
                            CustomerRole.MemberId = Customer.Id;
                            CustomerRole.RoleId   = role.Id;
                            _context.MemberRoles.Add(CustomerRole);
                            _context.SaveChanges();
                        }
                    }


                    if (IsClient(Customer.Phone, Customer.Password))
                    {
                        var data = new ClientLoginViewModel {
                            UserPhone = Customer.Phone, Password = Customer.Password, UserName = Customer.FullName
                        };
                        TempData["LoginData"] = JsonConvert.SerializeObject(data);
                        return(RedirectToAction(nameof(Index)));
                    }
                    //else
                    //{
                    //    ModelState.AddModelError("UserPhone", "رقم الهاتف أو كلمة المرور غير صحيحة");
                    //    return View();
                    //}

                    return(RedirectToAction(nameof(Index)));
                }

                ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", client.CityId);
                return(View(client));
            }
            catch (Exception ex)
            {
                return(RedirectToAction(nameof(Index)));
            }
        }