Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,LastName,Email,PhoneNumber,Position,Salary,AddressID")] EmployeesViewModel employee)
        {
            if (id != employee.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(EmployeeMapper.MapViewToEmployee(employee));
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!EmployeeExists(employee.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(employee));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditProfile(long id, [Bind("id,Country,UserId,DateOfBurth,PersonalWebUrl,UrlImage")] UserProfile userProfile, IFormFile img)
        {
            if (id != userProfile.id)
            {
                return(NotFound());
            }

            string userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (!string.IsNullOrEmpty(userId))
            {
                try
                {
                    string newFileName = string.Empty;
                    if (img != null && img.Length > 0)
                    {
                        string fn = img.FileName;
                        if (IsImageValidate(fn))
                        {
                            string extension = Path.GetExtension(fn);
                            newFileName = Guid.NewGuid().ToString() + extension;
                            string filename = Path.Combine(host.WebRootPath + "/images/user", newFileName);
                            await img.CopyToAsync(new FileStream(filename, FileMode.Create));

                            ViewBag.msg = "";
                        }
                        else
                        {
                            ViewBag.msg = "الملفات المسموح بها : png, jpeg, jpg, gif, bmp";
                            return(View());
                        }
                    }
                    else
                    {
                        newFileName = oldImage;
                    }

                    userProfile.UrlImage = newFileName;
                    userProfile.UserId   = userId;
                    db.Update(userProfile);
                    await db.SaveChangesAsync();

                    return(RedirectToAction(nameof(UserControl)));
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserProfileExists(userProfile.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }


            return(View(userProfile));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,TransactionID,Type,ProductID,ProductNetPrice,ProductGrossPrice,Date")] Transaction transaction)
        {
            if (id != transaction.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(transaction);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TransactionExists(transaction.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(transaction));
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,firstName,lastName,UserName,Email,Address,Country,Zip")] BillingAddress billingAddress)
        {
            if (id != billingAddress.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(billingAddress);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BillingAddressExists(billingAddress.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(billingAddress));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Edit(int id, [Bind("id,cardType,cardName,cardNumber,expiration,cvv,cartId,billingId")] Payment payment)
        {
            if (id != payment.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(payment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PaymentExists(payment.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["cartId"]    = new SelectList(_context.Carts, "id", "id", payment.cartId);
            ViewData["billingId"] = new SelectList(_context.BillingAddresses, "id", "Address", payment.billingId);
            return(View(payment));
        }
        public async Task <IActionResult> Edit(int id, [Bind("id,catName")] Category category)
        {
            if (id != category.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(category);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategoryExists(category.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
        public async Task <IActionResult> EditRegSetting(int id, [Bind("id,isEmailConfirm,isRegisterOpen,MinimumPassLength,MaxPassLength,isDigit,isUpper,SendWelcomeMessage")] UserSetting userSetting)
        {
            userSetting.id = 1;
            if (id != userSetting.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    db.Update(userSetting);
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserSettingExists(userSetting.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Trade,CompanyEmail,Street,Town,PostalCode,Voivodeship,Country,OwnerID")] Company company)
        {
            if (id != company.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(CompanyMapper.MapCompanyToView(company, _context));
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CompanyExists(company.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(company));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Edit(int id, [Bind("id,SubCatName,catId")] SubCategory subCategory)
        {
            if (id != subCategory.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(subCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SubCategoryExists(subCategory.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["catId"] = new SelectList(_context.Categories, "id", "catName", subCategory.catId);
            return(View(subCategory));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,FirstName,LastName,ClientEmail,Street,Town,PostalCode,Voivodeship,Country, ownerID")] ClientsViewModel client)
        {
            if (id != client.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(ClientMapper.MapViewToClient(client));
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(client));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> Edit(string id, [Bind("id,RoleId,UserId")] UserRole userRole)
        {
            if (id != userRole.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(userRole);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserRoleExists(userRole.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["RoleId"] = new SelectList(_context.AppRoles, "id", "RoleName");
            ViewData["UserId"] = new SelectList(_context.AppUsers, "id", "UserName");
            return(View(userRole));
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description,NetPrice,GrossPrice")] ProductsViewModel product)
        {
            if (ModelState.IsValid)
            {
                _context.Update(ProductMapper.MapViewToProduct(product));
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(product));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> Edit(long id, string Auther, DateTime PostDate, int PostViews, int PostLike,
                                               string LikeUserName, string PostImg,
                                               [Bind("id,Title,PostContent,PostImg,Auther,PostDate,PostViews,PostLike,LikeUserName,SubId,IsPublish,ProductName,Price,Discoun")] Post post, IFormFile img)
        {
            if (id != post.id)
            {
                return(NotFound());
            }

            ViewBag.msg = string.Empty;
            string newFileName = string.Empty;

            if (img != null && img.Length > 0)
            {
                newFileName = img.FileName;
                if (IsImageValidate(newFileName))
                {
                    string filename = Path.Combine(host.WebRootPath + "/images/Post", newFileName);
                    await img.CopyToAsync(new FileStream(filename, FileMode.Create));
                }
                else
                {
                    ViewBag.msg = "الملفات المسموح بها : png, jpeg, jpg, gif, bmp";
                    return(View());
                }
            }

            try
            {
                try
                {
                    post.Auther       = Auther;
                    post.LikeUserName = LikeUserName;
                    post.PostDate     = PostDate;
                    if (!string.IsNullOrEmpty(newFileName))
                    {
                        post.PostImg = newFileName;
                    }
                    else
                    {
                        post.PostImg = PostImg;
                    }

                    post.PostLike  = PostLike;
                    post.PostViews = PostViews;
                    _context.Update(post);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch { }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostExists(post.id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            ViewData["SubId"] = new SelectList(_context.SubCategories, "id", "SubCatName", post.SubId);
            return(View(post));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Edit(string id, [Bind("id,UserName,Email,Password,PasswordConfirm,Phone,EmailConfirm")] AppUser appUser)
        {
            if (id != appUser.id)
            {
                return(NotFound());
            }

            Message    = string.Empty;
            successMsg = string.Empty;

            if (ModelState.IsValid)
            {
                try
                {
                    string input = appUser.Password;
                    if (input != pass)
                    {
                        appUser.Password        = AppHash.HashPassword(input);
                        appUser.PasswordConfirm = AppHash.HashPassword(input);
                    }

                    DataTable dt    = new DataTable();
                    Users     users = new Users();

                    if (user != appUser.UserName)
                    {
                        dt = users.CheckUserNameExist(appUser.UserName);
                        if (dt.Rows.Count > 0)
                        {
                            Message = "اسم المستخدم المدخل (" + appUser.UserName + ") مستعمل";
                            return(View());
                        }
                    }

                    if (email != appUser.Email)
                    {
                        if (IsEmailAddressExist(email))
                        {
                            Message = "البريد الالكتروني المدخل (" + appUser.Email + ") مستعمل";
                            return(View());
                        }
                    }

                    _context.Update(appUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AppUserExists(appUser.id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(appUser));
        }