Inheritance: Bzs.Portable.DataTransferObjects.Base.ItemDtoBase
コード例 #1
0
        /// <summary>
        /// Inserts a room.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <param name="accountId">The account identifier.</param>
        /// <returns>The result.</returns>
        public ResultDto InsertRoom(RoomEditDto itemToSave, Guid? accountId)
        {
            ResultDto result = new ResultDto();
            using (BzsEntityContainer ctx = this.CreateContainer())
            {
                RoomEntity entity = ctx.RoomSet.FirstOrDefault(f => f.Id == itemToSave.Id);
                if (entity != null)
                {
                    result.Error = "ERR-ROOM-ALREADY-EXISTS";
                    return result;
                }

                entity = new RoomEntity();
                entity.Id = itemToSave.Id;
                entity.AccountId = accountId;
                entity.Code = itemToSave.Code.Length > 10 ? itemToSave.Code.Substring(0, 9) : itemToSave.Code;
                entity.Caption = itemToSave.Caption.Length > 50 ? itemToSave.Caption.Substring(0, 49) : itemToSave.Caption;
                entity.ModDate = DateTime.Now;
                entity.ModUser = Environment.UserName;
                ctx.RoomSet.Add(entity);

                ctx.SaveChanges();
                result.Success = true;
            }

            return result;
        }
コード例 #2
0
        /// <summary>
        /// Updates a room.
        /// </summary>
        /// <param name="itemToSave">The item to save.</param>
        /// <returns>The result.</returns>
        public ResultDto UpdateRoom(RoomEditDto itemToSave)
        {
            this.SetResponseHeaderCacheExpiration();

            AccountPassword credentials = this.GetCredentialsFromRequest();
            AccountServerService accountService = new AccountServerService();
            Guid accountId = accountService.GetAccountId(credentials.Account);

            RoomServerService service = new RoomServerService();
            return service.UpdateRoom(itemToSave, accountId);
        }