public Dormitory UpdateSingle(Dormitory source)
        {
            var result = _context.Dormitories.Update(source);

            _context.SaveChanges();
            return(result.Entity);
        }
Пример #2
0
        public async Task <ActionResult <Dormitory> > PostDormitory(Dormitory dormitory)
        {
            _context.Dormitories.Add(dormitory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDormitory", new { id = dormitory.Id }, dormitory));
        }
Пример #3
0
 public Dormitory AssignDormitoryAsPorter(ApplicationUser user, Dormitory dormitory)
 {
     user.DormitoryPorterId = dormitory.DormitoryId;
     _context.Users.Update(user);
     _context.SaveChanges();
     return(_context.Users.Find(user.Id).DormitoryPorter);
 }
Пример #4
0
        public async Task <ActionResult <IEnumerable <Student> > > DeletDormitoryFromStudent(int dormitoryId, int studentId)
        {
            Dormitory dormitory = await context.Dormitories.FindAsync(dormitoryId);

            if (dormitory == null)
            {
                return(BadRequest("Dormitory does not exist"));
            }
            Student student = await context.Students.FindAsync(studentId);

            if (student == null)
            {
                return(BadRequest("Dormitory does not exist"));
            }
            if (student.DormitoryId != dormitoryId)
            {
                return(BadRequest("This student does not live here."));
            }

            student.DormitoryId          = null;
            context.Entry(student).State = EntityState.Modified;
            await context.SaveChangesAsync();

            return(Ok());
        }
Пример #5
0
 protected void btn_Delete_Click(object sender, EventArgs e)
 {
     try
     {
         try
         {
             string ids = this.hf_CheckIDS.Value.ToString();
             ids = ids.TrimEnd(',').TrimStart(',');
             foreach (string id in ids.Split(','))
             {
                 int       iid       = Convert.ToInt32(id);
                 Dormitory dormitory = db.Dormitory.FirstOrDefault(t => t.ID == iid);
                 if (dormitory != null)
                 {
                     db.Dormitory.Remove(dormitory);
                 }
             }
             db.SaveChanges();
             new SysLogDAO().AddLog(LogType.操作日志_删除, "成功删除宿舍信息", UserID);
         }
         catch
         {
             ShowMessage("删除失败");
             return;
         }
     }
     catch (Exception ex)
     {
         ShowMessage(ex.Message);
         new SysLogDAO().AddLog(LogType.系统日志, ex.Message, UserID);
     }
     DataListBind();
     this.hf_CheckIDS.Value = "";
 }
 public void BindInfo()
 {
     using (IFMPDBContext db = new IFMPDBContext())
     {
         SpotProblem spotproblem = db.SpotProblem.FirstOrDefault(x => x.SpId == SpID);
         if (spotproblem != null)
         {
             SpotCheck spotcheck = db.SpotCheck.FirstOrDefault(x => x.SpotId == spotproblem.SpotId);
             Dormitory dormitory = db.Dormitory.FirstOrDefault(x => x.ID == spotcheck.DormitoryId);
             this.ltl_DorName.Text    = dormitory.DormiName.ToString();
             this.ltl_ProDesc.Text    = spotproblem.ProDesc.ToString();
             this.ltl_DutyUser.Text   = spotproblem.DutyUser == null ? "" : db.User.FirstOrDefault(t => t.ID.ToString() == spotproblem.DutyUser).RealName;
             this.ltl_SState.Text     = (spotproblem.IsreView == true ? "是" : "否");
             this.ltl_CreateUser.Text = spotproblem.CreateUser == null ? "" : db.User.FirstOrDefault(t => t.ID.ToString() == spotproblem.CreateUser).RealName;
             this.ltl_CreateDate.Text = spotproblem.CreateDate == null ? "" : spotproblem.CreateDate.Value.ToString("yyyy-MM-dd");
             this.ltl_ReviewUser.Text = spotproblem.ReviewUser == null ? "" : db.User.FirstOrDefault(t => t.ID.ToString() == spotproblem.ReviewUser).RealName;
             this.ltl_ReviewDate.Text = spotproblem.ReviewDate == null ? "" : spotproblem.ReviewDate.Value.ToString("yyyy-MM-dd");
             this.ltl_ReviewMemo.Text = spotproblem.ReviewMemo == null ? "" : spotproblem.ReviewMemo.ToString();
             if (string.IsNullOrEmpty(spotproblem.SImage))
             {
                 this.img.ImageUrl = "";
                 this.img.Visible  = false;
             }
             else
             {
                 this.img.ImageUrl = spotproblem.SImage.Length < 8 ? spotproblem.SImage : (spotproblem.SImage.ToString().Substring(0, 8) == "Templete" ? "../../DormitoryAPP/" + spotproblem.SImage : spotproblem.SImage);
             }
         }
     }
 }
Пример #7
0
        public OperationResult Add(BuildDto model)
        {
            if (ExistBuildCode(model.dorm_core) == false)
            {
                return(new OperationResult(OperationResultType.Error, "名称重复!"));
            }
            Dormitory dorm = new Dormitory();

            dorm.dorm_Code     = model.dorm_core;
            dorm.dorm_Level    = 1;
            dorm.dorm_ParentId = null;
            if (model.dorm_levels > 0)
            {
                dorm.dorm_State = "closed";
            }
            else
            {
                dorm.dorm_State = "open";
            }
            dorm = RecursionDormGeneral(dorm, model);
            try {
                this._dormRepository.Add(dorm);
                return(new OperationResult(OperationResultType.Success, "新增成功!", new DormitoryDto {
                    id = dorm.Id, text = dorm.dorm_Code, level = dorm.dorm_Level, pid = dorm.dorm_ParentId, state = dorm.dorm_State
                }));
            } catch (Exception e) {
                return(new OperationResult(OperationResultType.Error, "新增保存失败!", e));
            }
        }
        public void IsGetable()
        {
            object    id       = 654456; //insert testable adminID
            Dormitory response = repository.Read(id);

            Assert.NotNull(response);
        }
        public JsonResult update(String studentNum, Dormitory dormitory)
        {
            //获取学生信息  得到原本宿舍信息
            Student student = db.Students.Find(studentNum);

            if (student == null)
            {
                return(Json(ResultMap.errorMsg("查无此人"), JsonRequestBehavior.AllowGet));
            }
            try
            {
                //保存学生原本宿舍信息
                string buildingNum  = student.buildingNum;
                string dormitoryNum = student.dormitoryNum;
                //修改学生信息
                student.buildingNum  = dormitory.buildingNum;
                student.dormitoryNum = dormitory.dormitoryNum;
                //修改原本宿舍和新宿舍 已住人数   因为mdoel定义时  dormitorynum为1所以参数放前面
                Dormitory old = db.Dormitories.Find(dormitoryNum, buildingNum);
                old.residentNum = old.residentNum - 1;
                Dormitory newd = db.Dormitories.Find(dormitory.dormitoryNum, dormitory.buildingNum);
                newd.residentNum = newd.residentNum + 1;
                //保存修改
                db.SaveChanges();
            }
            catch (Exception e)
            {
                return(Json(ResultMap.errorMsg("数据库错误"), JsonRequestBehavior.AllowGet));
            }
            return(Json(ResultMap.OK(), JsonRequestBehavior.AllowGet));
        }
        public Dormitory GetDormitoryByNumber(int number)
        {
            _logger.LogInfo($"Getting dormitory by number {number}");

            var query     = "SELECT * FROM [Dormitories] WHERE [Number] = " + number;
            var dormitory = new Dormitory();

            using (var reader = _dbConnection.ExecuteReader(query))
            {
                while (reader.Read())
                {
                    dormitory = new Dormitory()
                    {
                        Id          = Convert.ToInt32(reader["Id"]),
                        Description = reader["Description"].ToString(),
                        Address     = reader["Address"].ToString(),
                        Number      = Convert.ToInt32(reader["Number"]),
                        Comendant   = _administratorService.GetAdministratorById(Convert.ToInt32(reader["ComendantId"])),
                        Floors      = _floorService.GetFloorsByDormitoryId(Convert.ToInt32(reader["Id"]))
                    };
                }
            }

            return(dormitory);
        }
Пример #11
0
        public async Task <IActionResult> PutDormitory(int id, Dormitory dormitory)
        {
            if (id != dormitory.Id)
            {
                return(BadRequest());
            }

            DormValid valid = new DormValid(_context, dormitory);

            if (valid.Valid() == false)
            {
                return(BadRequest("This Dormitory is already exist"));
            }

            _context.Entry(dormitory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DormitoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #12
0
        public ArrayList GetAllDormitories()
        {
            ArrayList     dormitories = new ArrayList();
            SqlConnection conn        = new SqlConnection();

            conn.ConnectionString = dbConnStr;
            conn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = "Select * from T_Dormitory";
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                Dormitory dor = new Dormitory();
                dor.Dorid    = (int)dr[0];
                dor.Dorhonor = dr[1].ToString();
                dor.Blockno  = (int)dr[2];
                dormitories.Add(dor);
            }
            dr.Close();
            conn.Close();
            return(dormitories);
        }
Пример #13
0
        private void GetDormFromSpreadSheet(int row, ExcelWorksheet sheet, int EventId)
        {
            Dormitory h = new Dormitory();

            h.Capacity = Convert.ToInt32(sheet.Cells[COLUMN_CAPACITE + Convert.ToString(row)].Value);
            h.Name     = (string)sheet.Cells[COLUMN_NAME + Convert.ToString(row)].Value;
            h.EventId  = EventId;

            try
            {
                h.DormType = Convertors.GetDormirtoryType((string)sheet.Cells[TYPE_DORM + Convert.ToString(row)].Value.ToString().ToLowerInvariant());
            }
            catch (Exception)
            {
                h.DormType = DormitoryTypeEnum.NONE;
            }

            try
            {
                h.DormCategory = Convertors.GetDormirtoryCategory((string)sheet.Cells[CATEGORY_DORM + Convert.ToString(row)].Value.ToString().ToLowerInvariant());
            }
            catch (Exception)
            {
                h.DormCategory = DormitoryCategoryEnum.MATELAS;
            }

            h.Persist();
        }
Пример #14
0
        public async Task <IActionResult> PutDormitory(int id, Dormitory dormitory)
        {
            if (id != dormitory.Id)
            {
                return(BadRequest());
            }

            _context.Entry(dormitory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DormitoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #15
0
 public Dormitory AssignManager(ApplicationUser user, Dormitory dormitory)
 {
     dormitory.Manager       = user;
     user.DormitoryManager   = dormitory;
     user.DormitoryManagerId = dormitory.DormitoryId;
     return(dormitory);
 }
Пример #16
0
 public Dormitory AssignDormitoryAsPorter(ApplicationUser user, Dormitory dormitory)
 {
     user.DormitoryPorter   = dormitory;
     user.DormitoryPorterId = dormitory.DormitoryId;
     dormitory.Porters?.Add(user);
     return(dormitory);
 }
Пример #17
0
        protected Dictionary <int, Dormitory> GetDorms(string[] dormLines)
        {
            try
            {
                Dictionary <int, Dormitory> ret = new Dictionary <int, Dormitory>();
                foreach (string line in dormLines)
                {
                    string[] aDorm = line.Split(',');
                    int      id    = int.Parse(aDorm[0]);
                    ret[id] = new Dormitory
                    {
                        IdEvent     = EVENTID,
                        IdDormitory = id,
                        Name        = aDorm[1],
                        Capacity    = int.Parse(aDorm[2]),
                        DormType    = (DormitoryTypeEnum)int.Parse(aDorm[3])
                    };
                }

                return(ret);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #18
0
        public async Task <bool> CheckDormitoryMembership(ClaimsPrincipal user, Dormitory dormitory)
        {
            var authorizationResult =
                await _authorizationService.AuthorizeAsync(user, dormitory, AuthPolicies.DormitoryMembership);

            return(authorizationResult.Succeeded);
        }
Пример #19
0
 public AnnouncementsList(List <Announcement> list, Dormitory dormitory)
 {
     Dormitory         = dormitory;
     Announcements     = list;
     AnnouncementToAdd = new Announcement()
     {
         Dormitory   = dormitory,
         DormitoryId = dormitory.DormitoryId
     };
 }
        public void IsDeleteable()
        {
            object id = 6546;//test object to be deleted id
            HttpResponseMessage response = repository.Delete(id);
            string    jsonContents       = response.Content.ReadAsStringAsync().Result;
            Dormitory deletedDormitory   = JsonConvert.DeserializeObject <Dormitory>(jsonContents);

            Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.Created, "Dormitory deletion test has failed.");
            Assert.Equals(deletedDormitory.ID, id);
        }
Пример #21
0
        /// <summary>
        /// 取得宿舍树
        /// </summary>
        /// <param name="dorm"></param>
        /// <returns></returns>
        private List <Dormitory> GetDormitoriesById(long Id)
        {
            List <Dormitory> _dormitories    = GetChildren(Id);
            List <Dormitory> _sumDormitories = new List <Dormitory>();
            Dormitory        _dorm           = this._dormRepository.GetByKey(Id);

            _sumDormitories.Add(_dorm);
            _sumDormitories = RecursionDormitories(_dormitories, _sumDormitories);
            return(_sumDormitories);
        }
Пример #22
0
        public Dormitory AddSingle(Dormitory source)
        {
            var maxId = Dormitories.Max(x => x.DormitoryId);

            source.DormitoryId = maxId + 1;

            _dormitories.Add(source);

            return(source);
        }
Пример #23
0
 public IActionResult Create([Bind("DormitoryID,Name,Address,ZipCode,City")]
                             Dormitory dormitory)
 {
     if (!ModelState.IsValid)
     {
         return(View(dormitory));
     }
     _dormitoryRepo.AddSingle(dormitory);
     return(RedirectToAction(nameof(Index)));
 }
Пример #24
0
        public NewDormPage()
        {
            InitializeComponent();

            dorm = new Dormitory
            {
                Name = "DormName"
            };

            BindingContext = this;
        }
Пример #25
0
 public ActionResult CreateDormitory([Bind(Include = "Name,Adress")] Dormitory dormitory)
 {
     if (IsLoggedOn())
     {
         if (dormitoryRepository.Create((dormitory)).ReasonPhrase == "Created")
         {
             return(RedirectToAction("Successful"));
         }
     }
     return(RedirectToAction("LoginForm", "Main"));
 }
Пример #26
0
 private static RoomsViewModel CreateRoomsViewModel(int id, Dormitory dormitory)
 {
     return(new RoomsViewModel()
     {
         ErrorMessage = "",
         Dormitory = dormitory,
         RoomToAdd = new Room()
         {
             DormitoryId = id,
         }
     });
 }
Пример #27
0
        public Dormitory UpdateSingle(Dormitory source)
        {
            var dormitory = Dormitories.SingleOrDefault(x => x.DormitoryId == source.DormitoryId);

            if (dormitory == null)
            {
                return(null);
            }
            _dormitories.Remove(dormitory);
            _dormitories.Add(source);
            return(source);
        }
Пример #28
0
        public void UpdateDormitory(Dormitory dor)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = dbConnStr;
            conn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = String.Format("Update T_Dormitory Set dorhonor = '{0}',blockno = {1} where dorid= {2}", dor.Dorhonor, dor.Blockno, dor.Dorid);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
Пример #29
0
        public void AddDormitory(Dormitory dor)
        {
            SqlConnection conn = new SqlConnection();

            conn.ConnectionString = dbConnStr;
            conn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = conn;
            cmd.CommandText = String.Format("Insert T_Dormitory values({0},'{1}',{2})", dor.Dorid, dor.Dorhonor, dor.Blockno);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
Пример #30
0
        public async Task <ActionResult <Dormitory> > PostDormitory(Dormitory dormitory)
        {
            DormValid valid = new DormValid(_context, dormitory);

            if (valid.Valid() == false)
            {
                return(BadRequest("This dormitory is already exist"));
            }
            _context.Dormitory.Add(dormitory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDormitory", new { id = dormitory.Id }, dormitory));
        }