Ejemplo n.º 1
0
        public AjaxResult allocateasset(
            string asset,
            string project,
            DateTime start,
            DateTime end,
            string status,
            bool ignoreconflicts = false)
        {
            // Get allocations for given date
            string resultValue = "success";

            bool confilictingAllocationFound = false;

            if (!ignoreconflicts)
            {
                DBQuery query = new DBQuery("dailyresourcingwidget", "getassetallocation");
                query.AddParameter("asset", new ObjectId(asset));
                query.AddParameter("start", start);
                query.AddParameter("end", end);

                DBResponse result = query.FindAsync(new DBCallProperties()
                {
                    RunWithPrivileges = 5
                }).Result;

                if (result["allocationentry"].Count > 0)
                {
                    confilictingAllocationFound = true;
                }
            }

            if (confilictingAllocationFound)
            {
                resultValue = "conflict";
            }
            else
            {
                var newAllocation = new DBDocument("allocationentry");
                newAllocation.AddRelation("asset", asset);
                newAllocation.AddRelation("project", project);

                newAllocation["starttimestamp"] = start;
                newAllocation["endtimestamp"]   = end;

                newAllocation.UpdateDatabase();
            }

            return(new AjaxResult(resultValue));
        }
Ejemplo n.º 2
0
        public ActionResult adddetail(string parent, string paytype, int duration = 0, int price = 0)
        {
            if (string.IsNullOrEmpty("parent"))
            {
                return(new AjaxResult("Missing parent when adding detail", System.Net.HttpStatusCode.InternalServerError));
            }

            if (string.IsNullOrEmpty("paytype"))
            {
                return(new AjaxResult("Missing paytype when adding detail", System.Net.HttpStatusCode.InternalServerError));
            }

            if (duration == 0 && price == 0)
            {
                return(new AjaxResult("Missing duration and price when adding detail", System.Net.HttpStatusCode.InternalServerError));
            }

            DBDocument detail = new DBDocument("timesheetentry");

            if (duration != 0)
            {
                detail["duration"] = duration;
            }

            if (price != 0)
            {
                detail["price"] = price;
            }

            detail.AddRelation("user", Runtime.SessionManager.CurrentUser[DBQuery.Id]);
            detail.AddRelation("timesheetentrydetailpaytype", paytype);
            detail.AddRelation("parent", parent);

            detail.UpdateDatabase();

            // Todo: handle errors
            return(new AjaxResult("success"));
        }
Ejemplo n.º 3
0
        public ActionResult editdetail(string id, string paytype, int duration = 0, int price = 0)
        {
            if (string.IsNullOrEmpty("id"))
            {
                return(new AjaxResult("Missing id when editing detail", System.Net.HttpStatusCode.InternalServerError));
            }

            if (string.IsNullOrEmpty("paytype"))
            {
                return(new AjaxResult("Missing paytype when editing detail", System.Net.HttpStatusCode.InternalServerError));
            }

            if (duration == 0 && price == 0)
            {
                return(new AjaxResult("Missing duration and price when editing detail", System.Net.HttpStatusCode.InternalServerError));
            }

            DBDocument detail = DBDocument.FindOne("timesheetentry", id);

            if (detail == null)
            {
                return(new AjaxResult("Could not find detail when editing detail", System.Net.HttpStatusCode.InternalServerError));
            }

            if (duration != 0)
            {
                detail["duration"] = duration;
            }

            if (price != 0)
            {
                detail["price"] = price;
            }

            detail.AddRelation("timesheetentrydetailpaytype", paytype);

            detail.UpdateDatabase();

            // Todo: handle errors
            return(new AjaxResult("success"));
        }