Ejemplo n.º 1
0
        public void UpdateItem(string id)
        {
            if (!master.isAdmin)
            {
                master.ShowErrorMessage("Not authorized.");
                return;
            }

            EventDay item = null;

            item = dbContext.EventDays.Find(int.Parse(id));
            if (item == null)
            {
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
                return;
            }

            TryUpdateModel(item);

            if (ModelState.IsValid)
            {
                dbContext.Entry(item).State = EntityState.Modified;
                dbContext.SaveChanges();
                master.ShowSuccessMessage("Item updated");
                this.DataBind();
            }
        }
Ejemplo n.º 2
0
        public void GridViewRoutes_DeleteItem(int id)
        {
            var item = data.Routes.Find(id);
            var dependentEventsIds  = data.EventDays.Where(x => x.MainRouteId == item.Id).Select(x => x.EventId).ToList();
            var dependentEventNames = data.Events.Where(x => dependentEventsIds.Contains(x.Id)).Select(x => x.Name).ToArray();

            if (dependentEventNames.Length > 0)
            {
                string eventNamesString = string.Join(", ", dependentEventNames);
                master.ShowErrorMessage($"Route cannot be deleted because it is main route in event {eventNamesString}");
                return;
            }

            data.Routes.Remove(item);
            data.SaveChanges();
            master.ShowSuccessMessage("Item deleted");
            this.DataBind();
        }
Ejemplo n.º 3
0
        public void UpdateItem(string id)
        {
            if (!master.isAdmin && id != User.Identity.GetUserId())
            {
                master.ShowErrorMessage("Not authorized.");
                return;
            }

            var  user = data.Users.Find(id);
            User item = null;

            item = data.Users.Find(id);
            if (item == null)
            {
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
                return;
            }

            TryUpdateModel(item);

            if (ModelState.IsValid)
            {
                var fileUploadControl = (FileUpload)FormViewUserDetails.FindControl("FileUploadControl");

                if (fileUploadControl.HasFile)
                {
                    string fileName = user.UserName + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".jpg";
                    fileUploadControl.SaveAs(Server.MapPath("~/Uploaded_Files/") + fileName);
                    user.Avatar = fileName;
                }

                data.Entry(item).State = EntityState.Modified;
                data.SaveChanges();
                master.ShowSuccessMessage("Item updated");

                this.DataBind();
            }
        }
Ejemplo n.º 4
0
        public void UpdateItem(string id)
        {
            if (!master.isAdmin && id != User.Identity.GetUserId())
            {
                master.ShowErrorMessage("Not authorized.");
                return;
            }

            //var user = data.Users.Find(id);
            User user = null;

            user = data.Users.Find(id);
            if (user == null)
            {
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", id));
                return;
            }

            TryUpdateModel(user);

            if (ModelState.IsValid)
            {
                var fileUploadControl = (FileUpload)FormViewUserDetails.FindControl("FileUploadControl");

                if (fileUploadControl.HasFile)
                {
                    string fileName = user.UserName + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".jpg";
                    fileUploadControl.SaveAs(Server.MapPath("~/Uploaded_Files/") + fileName);
                    user.Avatar = fileName;
                }

                user.Events.Clear();
                var lbEvents = (ListBox)FormViewUserDetails.FindControl("ListBoxEditEvents");
                foreach (ListItem ev in lbEvents.Items)
                {
                    var evId       = int.Parse(ev.Value);
                    var eventToAdd = data.Events.FirstOrDefault(x => x.Id == evId);
                    user.Events.Add(eventToAdd);
                }

                data.Entry(user).State = EntityState.Modified;
                data.SaveChanges();
                master.ShowSuccessMessage("Item updated");

                this.DataBind();
            }
        }