Example #1
0
        public IQueryable Get(ODataQueryOptions <FinanceDocument> option)
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            //var query = from hmem in _context.HomeMembers
            //            where hmem.User == usrName
            //            select new { HomeID = hmem.HomeID } into hids
            //            join docs in _context.FinanceDocument on hids.HomeID equals docs.HomeID
            //            select docs;
            var query = from hmem in _context.HomeMembers
                        where hmem.User == usrName
                        select new { HomeID = hmem.HomeID, User = hmem.User, IsChild = hmem.IsChild } into hmems
            join docs in _context.FinanceDocument
            on hmems.HomeID equals docs.HomeID
            where (hmems.IsChild == true && hmems.User == docs.Createdby) ||
            hmems.IsChild == null ||
            hmems.IsChild == false
            select docs;

            return(option.ApplyTo(query));
        }
Example #2
0
        public IQueryable <LearnCategory> Get()
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
            }
            catch
            {
                // Do nothing
                usrName = String.Empty;
            }

            if (String.IsNullOrEmpty(usrName))
            {
                return(_context.LearnCategories.Where(p => p.HomeID == null));
            }

            var rst0 = from ctgy in _context.LearnCategories
                       where ctgy.HomeID == null
                       select ctgy;
            var rst1 = from hmem in _context.HomeMembers
                       where hmem.User == usrName
                       select new { HomeID = hmem.HomeID } into hids
            join ctgy in _context.LearnCategories on hids.HomeID equals ctgy.HomeID
            select ctgy;

            return(rst0.Union(rst1));
        }
Example #3
0
        public async Task <IActionResult> Put([FromODataUri] int id, [FromBody] BlogCollection update)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            // User
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
                if (String.CompareOrdinal(update.Owner, usrName) != 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            // Check ID
            if (id != update.ID)
            {
                return(BadRequest());
            }

            _context.Entry(update).State = EntityState.Modified;
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.BlogCollections.Any(p => p.ID == id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(update));
        }
        public IQueryable Get(ODataQueryOptions <FinanceDocumentItem> option)
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            var rst =
                from hmem in _context.HomeMembers
                where hmem.User == usrName
                select new { HomeID = hmem.HomeID } into hids
            join orders in _context.FinanceOrder on hids.HomeID equals orders.HomeID
                select new { HomeID = orders.HomeID, ID = orders.ID } into orderids
            join srules in _context.FinanceOrderSRule on orderids.ID equals srules.OrderID
            select srules;

            return(option.ApplyTo(rst));
        }
Example #5
0
        public IQueryable <BlogPostTag> Get()
        {
            // User
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            var tags = from post in _context.BlogPosts
                       where post.Owner == usrName
                       select new { PostID = post.ID } into postids
            join posttags in _context.BlogPostTags
            on postids.PostID equals posttags.PostID
            select posttags;

            return(tags);
        }
        public IQueryable Get(ODataQueryOptions <FinanceDocumentItem> option)
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            var rst =
                from hmem in _context.HomeMembers
                where hmem.User == usrName
                select new { hmem.HomeID } into hids
            join docs in _context.FinanceDocument on hids.HomeID equals docs.HomeID
                select new { docs.HomeID, docs.ID } into docids
            join items in _context.FinanceDocumentItem on docids.ID equals items.DocID
            select items;

            return(option.ApplyTo(rst));
        }
Example #7
0
        public SingleResult <HomeDefine> Get([FromODataUri] int id)
        {
            String usrName = "";

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);

                if (string.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            var hidquery = from hmem in _context.HomeMembers
                           join hdef in _context.HomeDefines on hmem.HomeID equals hdef.ID
                           where hmem.User == usrName && hmem.HomeID == id
                           select hdef;

            return(SingleResult.Create(hidquery));
        }
Example #8
0
        public SingleResult <LearnCategory> Get([FromODataUri] int id)
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
            }
            catch
            {
                // Do nothing
                usrName = String.Empty;
            }

            if (String.IsNullOrEmpty(usrName))
            {
                return(SingleResult.Create(_context.LearnCategories.Where(p => p.ID == id && p.HomeID == null)));
            }

            var rst = from hmem in _context.HomeMembers.Where(p => p.User == usrName)
                      from acntctgy in _context.LearnCategories.Where(p => p.ID == id && (p.HomeID == null || p.HomeID == hmem.HomeID))
                      select acntctgy;

            return(SingleResult.Create(rst));
        }
        public IQueryable <FinanceTransactionType> Get()
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
            }
            catch
            {
                // Do nothing
                usrName = String.Empty;
            }

            if (String.IsNullOrEmpty(usrName))
            {
                return(_context.FinTransactionType.Where(p => p.HomeID == null));
            }

            var rst0 = from acntctgy in _context.FinTransactionType
                       where acntctgy.HomeID == null
                       select acntctgy;
            var rst1 = from hmem in _context.HomeMembers
                       where hmem.User == usrName
                       select new { HomeID = hmem.HomeID } into hids
            join acntctgy in _context.FinTransactionType on hids.HomeID equals acntctgy.HomeID
            select acntctgy;

            return(rst0.Union(rst1));
        }
        public IQueryable Get(ODataQueryOptions <LearnObject> option)
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            var query = from hmem in _context.HomeMembers
                        where hmem.User == usrName
                        select new { HomeID = hmem.HomeID } into hids
            join objs in _context.LearnObjects on hids.HomeID equals objs.HomeID
            select objs;

            return(option.ApplyTo(query));
        }
        public IQueryable Get(ODataQueryOptions <FinanceOrder> option)
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            var query = from hmem in _context.HomeMembers
                        where hmem.User == usrName
                        select new { hmem.HomeID, hmem.IsChild } into hids
            join ords in _context.FinanceOrder on hids.HomeID equals ords.HomeID
            // where ( hids.IsChild == null || hids.IsChild == false)
            select ords;

            return(option.ApplyTo(query));
        }
        public IQueryable <FinanceReportByOrder> Get()
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            List <FinanceReportOrderGroupAndExpenseView> arsts
                = (from hmem in _context.HomeMembers
                   where hmem.User == usrName
                   select new { HomeID = hmem.HomeID } into hids
                   join bal in _context.FinanceReportOrderGroupAndExpenseView on hids.HomeID equals bal.HomeID
                   select bal).ToList();
            List <FinanceOrder> orders = (from hmem in _context.HomeMembers
                                          where hmem.User == usrName
                                          select new { HomeID = hmem.HomeID } into hids
                                          join ord in _context.FinanceOrder on hids.HomeID equals ord.HomeID
                                          select ord).ToList();

            List <FinanceReportByOrder> listRsts = new List <FinanceReportByOrder>();

            foreach (var ord in orders)
            {
                var rst2 = new FinanceReportByOrder();
                rst2.OrderID = ord.ID;

                arsts.ForEach(action =>
                {
                    if (action.OrderID == ord.ID)
                    {
                        if (action.IsExpense)
                        {
                            rst2.CreditBalance = -1 * action.Balance;
                        }
                        else
                        {
                            rst2.DebitBalance = action.Balance;
                        }
                    }
                });
                rst2.Balance = rst2.DebitBalance - rst2.CreditBalance;

                rst2.HomeID = ord.HomeID;

                listRsts.Add(rst2);
            }

            return(listRsts.AsQueryable <FinanceReportByOrder>());
        }
Example #13
0
        public IActionResult Deploy([FromODataUri] string owner)
        {
            // User
            string usrName = "";

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            if (!string.IsNullOrEmpty(owner))
            {
                if (String.CompareOrdinal(owner, usrName) != 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }

            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new NotFoundException("Owner not found");
            }

            var errstr = "";

            try
            {
                BlogDeployUtility.UpdatePostSetting(setting);
            }
            catch (Exception exp)
            {
                errstr = exp.Message;
            }

            // Return
            if (!string.IsNullOrEmpty(errstr))
            {
                throw new Exception(errstr);
            }

            return(Ok(""));
            //if (string.IsNullOrEmpty(errstr))
            //{

            //    return Ok();
            //}

            //throw new Exception(errstr);
        }
        public IActionResult GetRepeatedDatesWithAmountAndInterest([FromBody] RepeatDatesWithAmountAndInterestCalInput input)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            return(Ok(CommonUtility.WorkoutRepeatedDatesWithAmountAndInterest(input)));
        }
        public IActionResult GetRepeatedDates([FromBody] RepeatDatesCalculationInput input)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            return(Ok(CommonUtility.WorkoutRepeatedDates(input)));
        }
Example #16
0
        public async Task <IActionResult> Post([FromBody] FinanceDocument document)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            // Check document type, DP, Asset, loan document is not allowed
            if (document.DocType == FinanceDocumentType.DocType_AdvancePayment ||
                document.DocType == FinanceDocumentType.DocType_AdvanceReceive ||
                document.DocType == FinanceDocumentType.DocType_AssetBuyIn ||
                document.DocType == FinanceDocumentType.DocType_AssetSoldOut ||
                document.DocType == FinanceDocumentType.DocType_AssetValChg ||
                document.DocType == FinanceDocumentType.DocType_BorrowFrom ||
                document.DocType == FinanceDocumentType.DocType_LendTo)
            {
                throw new BadRequestException("Document type is not allowed");
            }

            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            var hms = _context.HomeMembers.Where(p => p.HomeID == document.HomeID && p.User == usrName).Count();

            if (hms <= 0)
            {
                throw new UnauthorizedAccessException();
            }

            if (!document.IsValid(this._context))
            {
                return(BadRequest());
            }

            document.CreatedAt = DateTime.Now;
            document.Createdby = usrName;
            _context.FinanceDocument.Add(document);
            await _context.SaveChangesAsync();

            return(Created(document));
        }
        public async Task <IActionResult> Patch([FromODataUri] int key, [FromBody] Delta <FinanceControlCenter> coll)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            var entity = await _context.FinanceControlCenter.FindAsync(key);

            if (entity == null)
            {
                return(NotFound());
            }

            // User
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
                if (String.CompareOrdinal(entity.Owner, usrName) != 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Patch it
            coll.Patch(entity);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_context.FinanceControlCenter.Any(p => p.ID == key))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Updated(entity));
        }
        public IQueryable Get(ODataQueryOptions <FinanceAccount> option)
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            var query = from hmem in _context.HomeMembers where hmem.User == usrName
                        select new { hmem.HomeID, hmem.User, hmem.IsChild } into hmems
            join acnts in _context.FinanceAccount
            on hmems.HomeID equals acnts.HomeID
            where (hmems.IsChild == true && hmems.User == acnts.Owner) ||
            !hmems.IsChild.HasValue ||
            hmems.IsChild == false
            select acnts;

#if DEBUG
            // For testing purpose
            //var query1 = from hmem in _context.HomeMembers
            //             where hmem.User == usrName
            //             select hmem;
            //var query1rst = query1.ToList<HomeMember>();

            //var query2 = from hmem in query1
            //             join acnts in _context.FinanceAccount
            //               on hmem.HomeID equals acnts.HomeID
            //             where (hmem.IsChild == true && hmem.User == acnts.Owner)
            //                   || !hmem.IsChild.HasValue
            //                   || hmem.IsChild == false
            //             select acnts;

            //var queryrst = query2.ToList<FinanceAccount>();
            //if (queryrst.Count <= 0)
            //{
            //}
#endif

            return(option.ApplyTo(query));
        }
        public async Task <IActionResult> Post([FromBody] FinanceTransactionType ctgy)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            // Check
            if (!ctgy.IsValid(this._context) || !ctgy.HomeID.HasValue)
            {
                throw new BadRequestException("Inputted ID mismatched");
            }

            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            var hms = _context.HomeMembers.Where(p => p.HomeID == ctgy.HomeID.Value && p.User == usrName).Count();

            if (hms <= 0)
            {
                throw new UnauthorizedAccessException();
            }

            if (!ctgy.IsValid(this._context))
            {
                throw new BadRequestException("Inputted Object IsValid failed");
            }

            ctgy.CreatedAt = DateTime.Now;
            ctgy.Createdby = usrName;
            _context.FinTransactionType.Add(ctgy);
            await _context.SaveChangesAsync();

            return(Created(ctgy));
        }
Example #20
0
        public async Task <IActionResult> Post([FromBody] BlogCollection coll)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            // User
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
                if (coll.Owner != null)
                {
                    if (String.CompareOrdinal(coll.Owner, usrName) != 0)
                    {
                        throw new UnauthorizedAccessException();
                    }
                }
                else
                {
                    coll.Owner = usrName;
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            _context.BlogCollections.Add(coll);
            await _context.SaveChangesAsync();

            return(Created(coll));
        }
Example #21
0
        public IActionResult ClearDeploy(int key)
        {
            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            var errstr = "";

            try
            {
                BlogDeployUtility.RevokePostDeliver(setting.DeployFolder, key);
            }
            catch (Exception exp)
            {
                errstr = exp.Message;
            }

            // Return
            if (!string.IsNullOrEmpty(errstr))
            {
                throw new Exception(errstr);
            }

            return(Ok(""));
            //throw new Exception(errstr);
        }
Example #22
0
        public async Task <IActionResult> Delete([FromODataUri] int key)
        {
            var cc = await _context.BlogPosts.FindAsync(key);

            if (cc == null)
            {
                throw new NotFoundException("HIHAPI: Record not found");
            }

            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
                if (String.CompareOrdinal(cc.Owner, usrName) != 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            //if (!cc.IsDeleteAllowed(this._context))
            //    return BadRequest();

            _context.BlogPosts.Remove(cc);
            await _context.SaveChangesAsync();

            return(StatusCode(204)); // HttpStatusCode.NoContent
        }
Example #23
0
        public async Task <IActionResult> Delete([FromODataUri] int key)
        {
            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            var hms = _context.HomeMembers.Where(p => p.HomeID == key && p.User == usrName).Count();

            if (hms <= 0)
            {
                throw new UnauthorizedAccessException();
            }

            var cc = await _context.HomeDefines.FindAsync(key);

            if (cc == null)
            {
                throw new NotFoundException("Inputted Object Not Found");
            }

            // Perform the checks
            if (!cc.IsDeleteAllowed(this._context))
            {
                throw new BadRequestException("Inputted Object IsDeleteAllowed Failed");
            }

            _context.HomeDefines.Remove(cc);
            await _context.SaveChangesAsync();

            return(StatusCode(204)); // HttpStatusCode.NoContent
        }
        public async Task <IActionResult> Post([FromBody] FinancePlan plan)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            // Check
            if (!plan.IsValid(this._context))
            {
                throw new BadRequestException("Check IsValid failed");
            }

            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            var hms = _context.HomeMembers.Where(p => p.HomeID == plan.HomeID && p.User == usrName).Count();

            if (hms <= 0)
            {
                throw new UnauthorizedAccessException();
            }

            plan.Createdby = usrName;
            plan.CreatedAt = DateTime.Now;
            _context.FinancePlan.Add(plan);
            await _context.SaveChangesAsync();

            return(Created(plan));
        }
        public async Task <IActionResult> Delete([FromODataUri] int key)
        {
            var cc = await _context.FinanceControlCenter.FindAsync(key);

            if (cc == null)
            {
                return(NotFound());
            }

            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check whether User assigned with specified Home ID
            var hms = _context.HomeMembers.Where(p => p.HomeID == cc.HomeID && p.User == usrName).Count();

            if (hms <= 0)
            {
                throw new UnauthorizedAccessException();
            }

            if (!cc.IsDeleteAllowed(this._context))
            {
                return(BadRequest());
            }

            _context.FinanceControlCenter.Remove(cc);
            await _context.SaveChangesAsync();

            return(StatusCode(204)); // HttpStatusCode.NoContent
        }
Example #26
0
        public IQueryable <FinanceTmpLoanDocument> Get()
        {
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            return(_context.FinanceTmpLoanDocument);
        }
Example #27
0
        public IQueryable <BlogPost> Get()
        {
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            return(_context.BlogPosts.Where(p => p.Owner == usrName));
        }
Example #28
0
        public SingleResult <BlogPost> Get([FromODataUri] int id)
        {
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            return(SingleResult.Create(_context.BlogPosts.Where(p => p.ID == id && p.Owner == usrName)));
        }
Example #29
0
        public async Task <IActionResult> Delete([FromODataUri] int key)
        {
            var record = await _context.BlogCollections.FindAsync(key);

            if (record == null)
            {
                return(NotFound());
            }

            // User
            string usrName;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
                if (String.CompareOrdinal(record.Owner, usrName) != 0)
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            // Check setting
            var setting = _context.BlogUserSettings.SingleOrDefault(p => p.Owner == usrName);

            if (setting == null)
            {
                throw new BadRequestException(" User has no setting ");
            }

            _context.BlogCollections.Remove(record);
            await _context.SaveChangesAsync();

            return(StatusCode(204)); // HttpStatusCode.NoContent
        }
Example #30
0
        public async Task <IActionResult> Post([FromBody] HomeDefine homedef)
        {
            if (!ModelState.IsValid)
            {
                HIHAPIUtility.HandleModalStateError(ModelState);
            }

            if (!homedef.IsValid(this._context))
            {
                throw new BadRequestException("Inputted object IsValid Failed");
            }

            // User
            String usrName = String.Empty;

            try
            {
                usrName = HIHAPIUtility.GetUserID(this);
                if (String.IsNullOrEmpty(usrName))
                {
                    throw new UnauthorizedAccessException();
                }
            }
            catch
            {
                throw new UnauthorizedAccessException();
            }

            homedef.Createdby = usrName;
            homedef.CreatedAt = DateTime.Now;
            foreach (var hmem in homedef.HomeMembers)
            {
                hmem.CreatedAt = homedef.CreatedAt;
                hmem.Createdby = usrName;
            }
            _context.HomeDefines.Add(homedef);

            await _context.SaveChangesAsync();

            return(Created(homedef));
        }