public ActionResult Create([Bind(Include = "buildingID,name,address,addressReference,country,state,city,district,apartmentQuantity,active,createDate,createUser,updateDate,updateUser")] Building building)
        {
            try
            {
                if (DataUtil.Validation())
                {
                    if (ModelState.IsValid)
                    {
                        building.createDate = DateTime.Now;
                        building.createUser = Helper.GetCurrentUser().userID;
                        db.Building.Add(building);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }

                    return(View(building));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch (Exception ex)
            {
                Error objError = new Error();
                objError.page        = "Buildings";
                objError.option      = "Create-2";
                objError.date        = DateTime.Now;
                objError.description = ex.Message;
                BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
                baseDataAccess.Insert(objError);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Create([Bind(Include = "roleID,name,active,createDate,createUser,updateDate,updateUser,selected")] Role role)
        {
            try
            {
                if (DataUtil.Validation())
                {
                    if (ModelState.IsValid)
                    {
                        role.createDate = DateTime.Now;
                        role.createUser = Helper.GetCurrentUser().userID;
                        db.Role.Add(role);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }

                    return(View(role));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch (Exception ex)
            {
                Error objError = new Error();
                objError.page        = "Roles";
                objError.option      = "Create-2";
                objError.date        = DateTime.Now;
                objError.description = ex.Message;
                BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
                baseDataAccess.Insert(objError);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 3
0
        public Material Create(Material material)
        {
            var result = context.Materials.Add(material);

            context.SaveChanges();
            return(result);
        }
Exemplo n.º 4
0
        public User Create(User user)
        {
            var result = context.Users.Add(user);

            context.SaveChanges();
            return(result);
        }
Exemplo n.º 5
0
 public ActionResult Create([Bind(Include = "postID,postCategoryID,title,content,active,createDate,createUser,updateDate,updateUser")] Post post)
 {
     try
     {
         if (DataUtil.Validation())
         {
             if (ModelState.IsValid)
             {
                 db.Post.Add(post);
                 db.SaveChanges();
                 return(RedirectToAction("Index"));
             }
             ViewBag.postCategoryID = new SelectList(db.PostCategory, "postCategoryID", "name", post.postCategoryID);
             return(View(post));
         }
         else
         {
             return(RedirectToAction("Login", "Home"));
         }
     }
     catch (Exception ex)
     {
         Error objError = new Error();
         objError.page        = "Post";
         objError.option      = "Create-2";
         objError.date        = DateTime.Now;
         objError.description = ex.Message;
         BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
         baseDataAccess.Insert(objError);
         return(RedirectToAction("Error", "Home"));
     }
 }
        public ActionResult Create([Bind(Include = "apartmentID,sectionID,name,active,createDate,createUser,updateDate,updateUser")] Apartment apartment)
        {
            try {
                if (DataUtil.Validation())
                {
                    if (ModelState.IsValid)
                    {
                        apartment.createDate = DateTime.Now;
                        apartment.createUser = Helper.GetCurrentUser().userID;
                        db.Apartment.Add(apartment);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }

                    ViewBag.sectionID = new SelectList(db.Section, "sectionID", "name", apartment.sectionID);
                    return(View(apartment));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch (Exception ex)
            {
                Error objError = new Error();
                objError.page        = "Apartments";
                objError.option      = "Create-2";
                objError.date        = DateTime.Now;
                objError.description = ex.Message;
                BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
                baseDataAccess.Insert(objError);
                return(RedirectToAction("Error", "Home"));
            }
        }
        public ActionResult Index(RoleOptionView objRoleOptionView)
        {
            try
            {
                if (DataUtil.Validation())
                {
                    RoleOptionView objRoleOptionView2 = new RoleOptionView();
                    try
                    {
                        if (Request.Form["ActionForm"] == "Registrar")
                        {
                            var RemoveAll = db.RoleOption.Where(x => x.roleID == objRoleOptionView.role.roleID);
                            db.RoleOption.RemoveRange(RemoveAll);
                            db.SaveChanges();

                            RoleOption objRoleOption = new RoleOption();
                            foreach (var item in objRoleOptionView.options)
                            {
                                if (item.selected)
                                {
                                    objRoleOption.roleID   = objRoleOptionView.role.roleID;
                                    objRoleOption.optionID = item.optionID;
                                    db.RoleOption.Add(objRoleOption);
                                    db.SaveChanges();
                                }
                            }



                            objRoleOptionView2.roleOptionList = db.RoleOption.Include(u => u.option).Include(u => u.role).Where(u => u.role.roleID == objRoleOptionView.role.roleID).ToList();
                            objRoleOptionView2.options        = db.Database.SqlQuery <Option>("select o.optionid, o.name, CAST(ISNULL((select 1 from roleOptions ro where ro.roleID = @roleID and ro.optionID = o.optionID),0) AS BIT) selected, o.active, o.createdate, o.createuser, o.updatedate, o.updateuser from options o where o.active = 1", new SqlParameter("@roleID", objRoleOptionView.role.roleID)).ToList();
                            objRoleOptionView2.role           = db.Role.Find(objRoleOptionView.role.roleID);

                            ModelState.Clear();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    return(View(objRoleOptionView2));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch (Exception ex)
            {
                Error objError = new Error();
                objError.page        = "RoleOptions";
                objError.option      = "Index-2";
                objError.date        = DateTime.Now;
                objError.description = ex.Message;
                BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
                baseDataAccess.Insert(objError);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 8
0
        public ActionResult Index(UserRoleView objUserRoleView)
        {
            try
            {
                if (DataUtil.Validation())
                {
                    UserRoleView objUserRoleView2 = new UserRoleView();
                    try
                    {
                        if (Request.Form["ActionForm"] == "Registrar")
                        {
                            var RemoveAll = db.UserRole.Where(x => x.userID == objUserRoleView.user.userID);
                            db.UserRole.RemoveRange(RemoveAll);
                            db.SaveChanges();

                            UserRole objUserRole = new UserRole();
                            foreach (var item in objUserRoleView.roles)
                            {
                                if (item.selected)
                                {
                                    objUserRole.userID = objUserRoleView.user.userID;
                                    objUserRole.roleID = item.roleID;
                                    db.UserRole.Add(objUserRole);
                                    db.SaveChanges();
                                }
                            }



                            objUserRoleView2.userRoleList = db.UserRole.Include(u => u.role).Include(u => u.user).Where(u => u.user.userID == objUserRoleView.user.userID).ToList();
                            objUserRoleView2.roles        = db.Database.SqlQuery <Role>("select r.roleid, r.name, CAST(ISNULL((select 1 from userRoles ur where ur.userID = @userID and ur.roleID = r.roleID),0) AS BIT) selected, r.active, r.createdate, r.createuser, r.updatedate, r.updateuser from roles r where r.active = 1 ", new SqlParameter("@userID", objUserRoleView.user.userID)).ToList();
                            objUserRoleView2.user         = db.User.Find(objUserRoleView.user.userID);

                            ModelState.Clear();
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    return(View(objUserRoleView2));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch (Exception ex)
            {
                Error objError = new Error();
                objError.page        = "UserRoles";
                objError.option      = "Index-2";
                objError.date        = DateTime.Now;
                objError.description = ex.Message;
                BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
                baseDataAccess.Insert(objError);
                return(RedirectToAction("Error", "Home"));
            }
        }
        public void AddBuilding()
        {
            var newBuilding = new Building(Year, CountFloors);

            _db.Buildings.Add(newBuilding);
            _db.SaveChanges();

            Buildings.Add(newBuilding);
            Vertices.Add(newBuilding.ToVertex());

            ToStartState();
        }
Exemplo n.º 10
0
        public void Execute(IJobExecutionContext context)
        {
            Debug.WriteLine("Time to update!");
            var db = new BuildingContext();

            var url        = "https://data.melbourne.vic.gov.au/resource/q8hp-qgps.json";
            var jsonString = Download_JSON(url);
            List <Buildinginfo> buildings = new List <Buildinginfo>();

            buildings = JsonConvert.DeserializeObject <
                List <Buildinginfo> >(jsonString);

            //Debug.WriteLine("Count: " + buildings.Count);
            //Buildinginfo b = buildings[0];
            //Debug.WriteLine("Building 1: " + b.suburb);

            //remove null rateings & duplicate records
            buildings = buildings.Where(b => b.accessibility_rating != null).ToList();
            buildings = buildings.DistinctBy(b => b.property_id).ToList();

            db.Database.ExecuteSqlCommand("TRUNCATE TABLE Buildinginfoes");
            foreach (Buildinginfo b in buildings)
            {
                db.Buildinginfoes.Add(b);
            }
            db.SaveChanges();
        }
Exemplo n.º 11
0
        public ActionResult Create([Bind(Include = "Name,Architect")] BuildingModel buildingModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Buildings.Add(buildingModel);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException dex)
            {
                //Log the error
                ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator.");
            }

            return(View(buildingModel));
        }
Exemplo n.º 12
0
 public User Create(User user)
 {
     using (var context
                = new BuildingContext(ConnectionString))
     {
         var result = context.Users.Add(user);
         context.SaveChanges();
         return(result);
     }
 }
Exemplo n.º 13
0
 public ActionResult Create(User user)
 {
     try
     {
         if (DataUtil.Validation())
         {
             if (ModelState.IsValid)
             {
                 db.User.Add(user);
                 db.SaveChanges();
                 UserRole objUserRole = new UserRole();
                 objUserRole.userID = user.userID;
                 objUserRole.roleID = 4;
                 db.UserRole.Add(objUserRole);
                 db.SaveChanges();
                 ApartmentUser objApartmentUser = new ApartmentUser();
                 objApartmentUser.userID      = user.userID;
                 objApartmentUser.apartmentID = user.apartmentID;
                 objApartmentUser.principal   = user.principal;
                 db.ApartmentUser.Add(objApartmentUser);
                 db.SaveChanges();
                 return(RedirectToAction("Index", new { id = user.apartmentID }));
             }
             return(View(user));
         }
         else
         {
             return(RedirectToAction("Login", "Home"));
         }
     }
     catch (Exception ex)
     {
         Error objError = new Error();
         objError.page        = "ApartmentUsers";
         objError.option      = "Create-2";
         objError.date        = DateTime.Now;
         objError.description = ex.Message;
         BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
         baseDataAccess.Insert(objError);
         return(RedirectToAction("Error", "Home"));
     }
 }
Exemplo n.º 14
0
 public bool Delete(int id)
 {
     using (var context
                = new BuildingContext(ConnectionString))
     {
         var user = context.Users.Find(id);
         user.IsDeleted = true;
         context.SaveChanges();
         return(user.IsDeleted);
     }
 }
Exemplo n.º 15
0
        public void SendV2(string chatID, string userReceive, string message)
        {
            var sender = ConnectedUsers.First(u => u.ID.Equals(Context.ConnectionId));

            Clients.All.broadcastMessage(chatID, sender.Name, userReceive, message);
            Chat objChat = new Chat();

            objChat.chatCode   = chatID;
            objChat.createDate = DateTime.Now;
            objChat.message    = "<div class='ui-chatbox-msg' style='display: block; max-width: 208px;'><b>" + sender.Name + ": </b><span>" + message + "</span></div>";
            db.Chat.Add(objChat);
            db.SaveChanges();
        }
Exemplo n.º 16
0
        public void Save(Report report)
        {
            var entity = _buildingContext.Reports.Include(r => r.Quantities).ToList().SingleOrDefault(r => r.Id == report.Id) ?? new Entities.Report();

            entity.CreatedDate  = DateTime.UtcNow;
            entity.ReportDate   = report.Date;
            entity.WorkersCount = report.NumberOfWorkers;
            entity.ReporterId   = report.ReporterId.Value;

            if (entity.Quantities != null)
            {
                entity.Quantities.RemoveAll(q => report.Work.All(w => w.EstimationId != q.EstimationId));
                foreach (var work in report.Work)
                {
                    var quantity = entity.Quantities.SingleOrDefault(q => q.EstimationId == work.EstimationId);
                    if (quantity != null)
                    {
                        quantity.Quantity = work.Quantity;
                    }
                    else
                    {
                        entity.Quantities.Add(new ReportQuantity
                        {
                            EstimationId = work.EstimationId,
                            Quantity     = work.Quantity
                        });
                    }
                }
            }
            else
            {
                entity.Quantities = report.Work.Select(w => new ReportQuantity
                {
                    EstimationId = w.EstimationId,
                    Quantity     = w.Quantity
                }).ToList();
            }

            if (report.Id == 0)
            {
                _buildingContext.Reports.Add(entity);
            }

            _buildingContext.SaveChanges();

            if (report.Id == 0)
            {
                report.SetId(entity.Id);
            }
        }
Exemplo n.º 17
0
        public void Create(FileStream stream, int mainContractorId)
        {
            var hssfwb = new XSSFWorkbook(stream);
            var sheet  = hssfwb.GetSheetAt(0);

            for (var i = sheet.FirstRowNum + 1; i <= sheet.LastRowNum; i++)
            {
                var row    = sheet.GetRow(i);
                var entity = new Estimation
                {
                    EstimationId = row.GetCell(0).ToString(),
                    SpecNumber   = row.GetCell(1).ToString(),
                    Description  = row.GetCell(2).ToString(),
                    Unit         = row.GetCell(3).ToString(),
                    Quantity     = (decimal)row.GetCell(4).NumericCellValue,
                    UnitPrice    = (decimal)row.GetCell(5).NumericCellValue,
                    Amount       = (decimal)row.GetCell(6).NumericCellValue,
                    CompanyId    = mainContractorId
                };
                _buildingContext.Estimations.Add(entity);
            }

            _buildingContext.SaveChanges();
        }
Exemplo n.º 18
0
 public string Post([FromBody] TblEntryoff tblEntryoff)
 {
     try
     {
         //  WebapiContext context = new WebapiContext();
         using (BuildingContext Context = new BuildingContext())
         {
             Context.TblEntryoffs.Add(tblEntryoff);
             Context.SaveChanges();
             return("success ");
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 19
0
        public ActionResult ImportKota(FormCollection formCollection)
        {
            var dataList = new List <Lokasi>();

            if (Request != null)
            {
                HttpPostedFileBase file = Request.Files["UploadKota"];
                if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName))
                {
                    string fileName        = file.FileName;
                    string fileContentType = file.ContentType;
                    byte[] fileBytes       = new byte[file.ContentLength];
                    var    data            = file.InputStream.Read(fileBytes, 0, Convert.ToInt32(file.ContentLength));
                    using (var package = new ExcelPackage(file.InputStream))
                    {
                        var currentSheet = package.Workbook.Worksheets;
                        var workSheet    = currentSheet.First();
                        var noOfCol      = workSheet.Dimension.End.Column;
                        var noOfRow      = workSheet.Dimension.End.Row;
                        for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
                        {
                            var listData = new Lokasi();
                            listData.ID         = Convert.ToInt32(workSheet.Cells[rowIterator, 1].Value);
                            listData.IDProvinsi = workSheet.Cells[rowIterator, 2].Value.ToString();
                            listData.Provinsi   = workSheet.Cells[rowIterator, 3].Value.ToString();
                            listData.Kota       = workSheet.Cells[rowIterator, 4].Value.ToString();
                            dataList.Add(listData);
                        }
                    }
                }
            }
            using (BuildingContext importDB = new BuildingContext())
            {
                foreach (var item in dataList)
                {
                    importDB.Lokasi.Add(item);
                }
                importDB.SaveChanges();
            }
            return(View("Index"));
        }
Exemplo n.º 20
0
        public ActionResult UpdatePassword(User objUser)
        {
            try
            {
                if (objUser.username == "" || objUser.password == "" || objUser.newpassword == "" || objUser.username == null || objUser.password == null || objUser.newpassword == null)
                {
                    objUser.result = 3;
                }
                else
                {
                    User oUser = new User();

                    oUser = db.User.FirstOrDefault(u => u.username.ToUpper() == objUser.username.ToUpper() && u.password == objUser.password);

                    if (objUser != null)
                    {
                        oUser.password        = objUser.newpassword;
                        db.Entry(oUser).State = EntityState.Modified;
                        db.SaveChanges();
                        objUser.result = 1;
                    }
                    else
                    {
                        objUser.result = 2;
                    }
                }
                return(View(objUser));
            }
            catch (Exception ex)
            {
                Error objError = new Error();
                objError.page        = "Home";
                objError.option      = "UpdatePassword-2";
                objError.date        = DateTime.Now;
                objError.description = ex.Message;
                BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
                baseDataAccess.Insert(objError);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 21
0
        public void GenerateEstimation()
        {
            var optionsBuilder = new DbContextOptionsBuilder <BuildingContext>();

            optionsBuilder.UseSqlServer("Server=.;Database=BuildingDatabase;User Id=sa;Password=Bubelsoft1");

            var buildingcontext = new BuildingContext(optionsBuilder.Options);

            var rand = new Random();

            for (var m = 1; m < 13; m++)
            {
                for (var i = 1; i < 15; i++)
                {
                    var guid        = Guid.NewGuid().ToString().Substring(0, 5);
                    var createdDate = DateTime.UtcNow;

                    var report = new Report
                    {
                        CreatedDate  = createdDate,
                        ReportDate   = new DateTime(2017, m, rand.Next(1, 27)),
                        WorkersCount = rand.Next(4, 20),
                        ReporterId   = 1,
                        Quantities   = new List <ReportQuantity>
                        {
                            new ReportQuantity
                            {
                                EstimationId = rand.Next(30000, 100000),
                                Quantity     = rand.Next(1, 10)
                            }
                        }
                    };

                    buildingcontext.Reports.Add(report);

                    buildingcontext.SaveChanges();
                }
            }
        }
Exemplo n.º 22
0
        public void AddNewProductionLineName(BuildingContext context, string LineName, int count)
        {
            List <ProductionLineName> _lineName = new List <ProductionLineName>();

            if (LineName == "L")
            {
                for (int i = 0; i < count; i++)
                {
                    _lineName.Add(new ProductionLineName
                    {
                        SystemCode  = $"L{i + 1}9",
                        LineCode    = $"L{i + 1}",
                        DisplayCode = $"L{i + 1}",
                    });
                }

                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LJ9",
                    LineCode    = "L1A",
                    DisplayCode = "L1",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LK9",
                    LineCode    = "L1B",
                    DisplayCode = "L1",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LH9",
                    LineCode    = "L2A",
                    DisplayCode = "L2",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LI9",
                    LineCode    = "L2A",
                    DisplayCode = "L2",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LL9",
                    LineCode    = "L3A",
                    DisplayCode = "L3",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LM9",
                    LineCode    = "L3B",
                    DisplayCode = "L3",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LN9",
                    LineCode    = "L4A",
                    DisplayCode = "L4",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LO9",
                    LineCode    = "L4B",
                    DisplayCode = "L4",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LP9",
                    LineCode    = "L5A",
                    DisplayCode = "L5",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LQ9",
                    LineCode    = "L5B",
                    DisplayCode = "L5",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LR9",
                    LineCode    = "L6A",
                    DisplayCode = "L6",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "LT9",
                    LineCode    = "L6B",
                    DisplayCode = "L6",
                });

                context.ProductionLineNames.AddRange(_lineName);
                context.SaveChanges();
                return;
            }

            if (LineName == "M")
            {
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "MA9", // begin H ->M
                    LineCode    = "M1",
                    DisplayCode = "M1",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "MB9", // begin H ->M
                    LineCode    = "M2",
                    DisplayCode = "M2",
                });
                _lineName.Add(new ProductionLineName
                {
                    SystemCode  = "MC9", // begin H ->M
                    LineCode    = "M3",
                    DisplayCode = "M3",
                });
            }

            //Line O
            for (int i = 0; i < count; i++)
            {
                if (LineName == "M")
                {
                    _lineName.Add(new ProductionLineName
                    {
                        SystemCode  = $"M{(char)(i + 72)}9", // begin H ->M
                        LineCode    = $"M{i + 1}A",
                        DisplayCode = $"M{i + 1}",
                    });
                    _lineName.Add(new ProductionLineName
                    {
                        SystemCode  = $"M{(char)(i + 72 + 1)}9",
                        LineCode    = $"M{i + 1}B",
                        DisplayCode = $"M{i + 1}",
                    });
                }
                else
                {
                    _lineName.Add(new ProductionLineName
                    {
                        SystemCode  = $"{LineName}{(char)(i + 65)}9",
                        LineCode    = $"{LineName}{i + 1}",
                        DisplayCode = $"{LineName}{i + 1}",
                    });
                }
            }
            context.ProductionLineNames.AddRange(_lineName);
            context.SaveChanges();
        }
Exemplo n.º 23
0
        public ActionResult Profile([Bind(Include = "userID,categoryUserID,name,lastname,username,password,active,email,dni,phonenumber,createDate,createUser,updateDate,updateUser")] User user, HttpPostedFileBase postedFile)
        {
            try
            {
                if (DataUtil.Validation())
                {
                    if (ModelState.IsValid)
                    {
                        var objUserEmail = db.User.FirstOrDefault(u => u.email == user.email && u.userID != user.userID);
                        if (objUserEmail != null)
                        {
                            user.messageErrorEmail = "El email ingresado ya existe!.";
                        }
                        else
                        {
                            user.updateDate = DateTime.Now;
                            user.updateUser = Helper.GetCurrentUser().userID;
                            user.name       = user.name.ToUpper();
                            user.lastname   = user.lastname.ToUpper();

                            user.imageURL        = System.Configuration.ConfigurationManager.AppSettings["userImgURL"] + user.userID.ToString() + ".jpg";
                            db.Entry(user).State = EntityState.Modified;
                            db.SaveChanges();

                            if (postedFile != null)
                            {
                                var    versions = new Dictionary <string, string>();
                                string path     = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["userImgURLFinal"]);
                                if (!Directory.Exists(path))
                                {
                                    Directory.CreateDirectory(path);
                                }
                                postedFile.SaveAs(path + Helper.GetCurrentUser().userID.ToString() + Path.GetExtension(postedFile.FileName));
                                versions.Add("", "maxwidth=120&maxheight=120&format=jpg");
                                foreach (var suffix in versions.Keys)
                                {
                                    postedFile.InputStream.Seek(0, SeekOrigin.Begin);
                                    ImageBuilder.Current.Build(
                                        new ImageJob(
                                            postedFile.InputStream,
                                            path + user.userID.ToString() + suffix,
                                            new Instructions(versions[suffix]),
                                            false,
                                            true));
                                }
                                ViewBag.Message = "File uploaded successfully.";
                            }
                        }
                        return(RedirectToAction("Profile"));
                    }
                    return(View(user));
                }
                else
                {
                    return(RedirectToAction("Login", "Home"));
                }
            }
            catch (Exception ex)
            {
                Error objError = new Error();
                objError.page        = "Users";
                objError.option      = "Edit-2";
                objError.date        = DateTime.Now;
                objError.description = ex.Message;
                BaseDataAccess <Error> baseDataAccess = new BaseDataAccess <Error>();
                baseDataAccess.Insert(objError);
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 24
0
        public void Building()
        {
            using (var context = new BuildingContext(Database))
            {
                if (context.Database.Exists())
                {
                    Console.WriteLine("BuildingContext is existing");
                    return;
                }

                context.Database.Create();
                Console.WriteLine("BuildingContext is created successfully");

                Building l = new Building
                {
                    Name            = "L",
                    ProductionLines = new List <ProductionLine>()
                };

                for (int i = 1; i <= 6; i++)
                {
                    l.ProductionLines.Add(new ProductionLine {
                        LineName = $"L{i}"
                    });
                }
                context.Buildings.Add(l);

                Building E = new Building
                {
                    Name            = "E",
                    ProductionLines = new List <ProductionLine>()
                };

                for (int i = 1; i <= 7; i++)
                {
                    E.ProductionLines.Add(new ProductionLine {
                        LineName = $"E{i}"
                    });
                }

                context.Buildings.Add(E);

                Building I = new Building
                {
                    Name            = "I",
                    ProductionLines = new List <ProductionLine>()
                };

                for (int i = 1; i <= 11; i++)
                {
                    I.ProductionLines.Add(new ProductionLine {
                        LineName = $"I{i}"
                    });
                }

                context.Buildings.Add(I);

                Building O = new Building
                {
                    Name            = "O",
                    ProductionLines = new List <ProductionLine>()
                };

                for (int i = 1; i <= 2; i++)
                {
                    O.ProductionLines.Add(new ProductionLine {
                        LineName = $"O{i}"
                    });
                }

                context.Buildings.Add(O);

                Building P = new Building
                {
                    Name            = "P",
                    ProductionLines = new List <ProductionLine>()
                };

                for (int i = 1; i <= 7; i++)
                {
                    P.ProductionLines.Add(new ProductionLine {
                        LineName = $"P{i}"
                    });
                }

                context.Buildings.Add(P);

                Building M = new Building
                {
                    Name            = "M",
                    ProductionLines = new List <ProductionLine>()
                };

                for (int i = 1; i <= 3; i++)
                {
                    M.ProductionLines.Add(new ProductionLine {
                        LineName = $"M{i}"
                    });
                }

                context.Buildings.Add(M);

                Building J = new Building
                {
                    Name            = "J",
                    ProductionLines = new List <ProductionLine>()
                };

                for (int i = 1; i <= 3; i++)
                {
                    J.ProductionLines.Add(new ProductionLine {
                        LineName = $"J{i}"
                    });
                }
                context.Buildings.Add(J);
                context.SaveChanges();


                // add line O
                AddNewProductionLineName(context, "O", 2);
                // add line P
                AddNewProductionLineName(context, "P", 7);
                // add line I
                AddNewProductionLineName(context, "L", 7);
                // add line E
                AddNewProductionLineName(context, "I", 11);
                // add line L
                AddNewProductionLineName(context, "J", 3);
                // add line J
                AddNewProductionLineName(context, "M", 3);
                // add line L
                AddNewProductionLineName(context, "E", 7);

                try
                {
                    context.Database.ExecuteSqlCommand("DROP TABLE [__MigrationHistory]");

                    context.SaveChanges();
                }
                catch { }
            }
        }